@milesroxas/design-hub 0.11.2 → 0.13.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 +8 -6
- package/core/prototype.test.ts +52 -0
- package/core/prototype.ts +59 -0
- package/core/review/model.ts +20 -0
- package/core/review/service.test.ts +262 -37
- package/core/review/service.ts +276 -52
- package/core/review/store.ts +12 -6
- package/core/review/suite-kv.ts +17 -0
- package/dist/core/prototype.d.ts +50 -0
- package/dist/core/prototype.js +38 -0
- package/dist/core/review/model.d.ts +22 -0
- package/dist/core/review/model.js +8 -0
- package/dist/core/review/service.d.ts +98 -18
- package/dist/core/review/service.js +248 -46
- package/dist/core/review/store.d.ts +10 -4
- package/dist/core/review/store.js +2 -2
- package/dist/core/review/suite-kv.d.ts +7 -0
- package/dist/core/review/suite-kv.js +12 -0
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +55 -69
- package/dist/scripts/lib/cli.js +5 -0
- 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 +35 -11
- package/dist/scripts/lib/fake-host.js +27 -13
- package/dist/scripts/lib/host.d.ts +13 -25
- package/dist/scripts/lib/host.js +15 -324
- package/dist/scripts/lib/studio-deps.d.ts +16 -0
- package/dist/scripts/lib/studio-deps.js +41 -16
- package/dist/scripts/lib/studios.d.ts +17 -5
- package/dist/scripts/lib/studios.js +25 -5
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +410 -0
- package/dist/scripts/people.d.ts +7 -4
- package/dist/scripts/people.js +147 -39
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +10 -4
- package/dist/scripts/studio.js +136 -22
- package/dist/server/api.d.ts +12 -13
- package/dist/server/api.js +141 -52
- package/dist/server/gate.d.ts +97 -0
- package/dist/server/gate.js +537 -0
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +9 -1
- package/dist/server/session.js +10 -3
- package/dist/server/stores/backends.d.ts +22 -0
- package/dist/server/stores/backends.js +96 -0
- package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
- package/dist/server/stores/index.d.ts +41 -0
- package/dist/server/stores/index.js +63 -0
- package/dist/server/stores/pglite.d.ts +16 -0
- package/dist/server/stores/pglite.js +98 -0
- package/dist/server/stores/postgres.d.ts +63 -0
- package/dist/server/stores/postgres.js +153 -0
- package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
- package/dist/vercel/files.js +1 -1
- package/dist/vercel/proxy.d.ts +6 -78
- package/dist/vercel/proxy.js +18 -359
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +22 -4
- package/package.json +3 -1
- package/shell/Index.tsx +29 -0
- package/shell/review/People.tsx +79 -49
- package/shell/review/Review.tsx +49 -1
- package/shell/review/ThreadCard.tsx +13 -1
- package/shell/review/client.ts +54 -21
- 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 +17 -6
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/.env.example +3 -0
- package/templates/studio/README.md +45 -13
- package/templates/studio/package.json +1 -1
- /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
- /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
package/README.md
CHANGED
|
@@ -72,11 +72,13 @@ A speculation rule in `shell/index.html` prefetches a prototype's page when its
|
|
|
72
72
|
|
|
73
73
|
## The studio site, and signing in
|
|
74
74
|
|
|
75
|
-
`miles-deploy` owns the steps; this is what they rest on. A project has no deployment of its own. A **studio** is one site on one hosting account, with one database (Upstash for Redis), one private file store (Vercel Blob), one `GATE_SECRET` and one apex domain, that serves every client of the studio; two studios share none of these. Its folder, made by `design-hub studio create` from `templates/studio/`, is thin like a project: one-line `proxy.ts`, `api/review.ts` and `api/files.ts` from `./vercel`, a `vercel.json`, a `studio.json` (id, slug, apex, team, DNS; no secret) and a gitignored `.env`. A machine finds its studios by slug in `~/.design-hub/studios.json`. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing.
|
|
75
|
+
`miles-deploy` owns the steps; this is what they rest on. A project has no deployment of its own. A **studio** is one site on one hosting account, with one database (Upstash for Redis, or Postgres: Neon, Supabase or any other, chosen at `studio create --kv`), one private file store (Vercel Blob), one `GATE_SECRET` and one apex domain, that serves every client of the studio; two studios share none of these. Its folder, made by `design-hub studio create` from `templates/studio/`, is thin like a project: one-line `proxy.ts`, `api/review.ts` and `api/files.ts` from `./vercel`, a `vercel.json`, a `studio.json` (id, slug, apex, team, DNS, the database's kind and the host; no secret) and a gitignored `.env`. A machine finds its studios by slug in `~/.design-hub/studios.json`. `design-hub signin` starts `vercel login`'s device sign-in in the background and returns its link, so the user clicks instead of typing.
|
|
76
76
|
|
|
77
|
-
A client's address is `<client>.<apex>` (or a codename under the apex, `client add --host`), and a project is `/<project>/` below it. `design-hub project link` writes `.design-hub/studio.json` in the project (studio, its id, client, project; committed). `design-hub share` builds the project with base `/<project>/`, uploads `dist/` under `c/<client>/<project>/<build>/` in the file store with a new random build id, checks every file is there, and only then points the project's record at that build, so a half-finished upload is never served; the live build and the two before it are kept. Every path on every client's host sits behind the gate, enforced on the server by Vercel Routing Middleware (`createStudioProxy` in `vercel/proxy.ts`, which the studio's `vercel.json` names as `proxy.entrypoint`). The host names the client, from one store lookup kept a minute per instance; a host no client has is the plain 404 before anything else is read. The files function and the review function run the gate's checks again themselves, in the order host, session, project, so neither trusts anything the gate set. A client-side gate was rejected because the bundle and the state behind it would still download.
|
|
77
|
+
A client's address is `<client>.<apex>` (or a codename under the apex, `client add --host`), and a project is `/<project>/` below it. `design-hub project link` writes `.design-hub/studio.json` in the project (studio, its id, client, project; committed). `design-hub share` builds the project with base `/<project>/`, uploads `dist/` under `c/<client>/<project>/<build>/` in the file store with a new random build id, checks every file is there, and only then points the project's record at that build, so a half-finished upload is never served; the live build and the two before it are kept. Every path on every client's host sits behind the gate, enforced on the server by the gate (`server/gate.ts`, free of any host: it answers each request with a decision), run as Vercel Routing Middleware by its adapter (`createStudioProxy` in `vercel/proxy.ts`, which the studio's `vercel.json` names as `proxy.entrypoint`). The host names the client, from one store lookup kept a minute per instance; a host no client has is the plain 404 before anything else is read. The files function and the review function run the gate's checks again themselves, in the order host, session, project, so neither trusts anything the gate set. A client-side gate was rejected because the bundle and the state behind it would still download.
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
Studio people have a host of their own, `studio.<apex>`, which `studio create` (or `studio deploy`, for an older studio) adds and proves as it proves a client's. Only Studio people sign in there; a Client, a cookie of a client's host, or none gets that host's sign-in page, word for word a client host's. Its page is the studio hub (`shell/studio/StudioHub.tsx`, built apart from the client hub under `_studio/`, so no client's host serves it): every client with its projects, an **Open** that hands the person off to the client's host (a one-time record in the client's keys, claimed once there within 60 seconds, which sets that host's own Studio cookie), and a **People** panel per client and one for the studio's own people, the review panel's People controls. Its review API answers `me`, `clients` and the people ops, each naming the client it is for with `client`, which the service checks as the handoff does (known, added, not archived) and answers as an unknown client otherwise; without `client` an op is the studio's own people. No client's host reads a `client` parameter.
|
|
80
|
+
|
|
81
|
+
Every person is named, and signs in with a one-time link that Studio makes in the review panel's People tab, on the studio hub, with `design-hub people` in a linked project, the studio folder or with `--studio`, or, for a client's first person, with `design-hub client add`. A Client's link is on their client's host, and signs in there only. A Studio person's is on `studio.<apex>` once it answers (on the linked client's host before then), and signs in on any host of the studio; the owner's first comes from the run that proves the studio host, and a new one from `people link <owner id> --studio <studio>`.
|
|
80
82
|
|
|
81
83
|
- **A link works once.** `GET /invite/<token>` shows who it is for and a Continue button, and uses nothing up, since mail and chat previews open links too. Continue is a same-origin `POST` that uses the link up, sets the session cookie and goes to `/`. The use is atomic: the store's delete is the claim, so of two requests with one link only the one whose delete removed it signs in. A used, expired or unknown link answers 404, as does a link for someone revoked or past their access end. An unused link lasts 14 days. The store keeps only a hash of each token (32 random bytes), so a read of the store signs nobody in.
|
|
82
84
|
- **A second device gets a second link** (`design-hub people link <id>`), and the first stays signed in. **Sign out everywhere** (`people sign-out <id>`) bumps the person's epoch, drops their unused links and returns one new link. **Revoke** ends their access everywhere.
|
|
@@ -87,12 +89,12 @@ Every person is named, and signs in with a one-time link that Studio makes in th
|
|
|
87
89
|
- **Internal prototypes.** Everything built from `prototypes/<slug>/` (its README, code, CSS, fixtures, lazy chunks and images) lands under `/_p/<slug>/`, its entry at `/_p/<slug>/entry.js`, and Studio's list of every slug at `/_p/all.js`; the shared bundle in `/assets/` names no prototype's folder (`vite/registry.ts`, `vite/boundary.ts`, `vite/settle.ts`; the build fails if a file breaks that). The exception is the walkthroughs: their compiled text and every feature's name sit in `/assets/` and reach every signed-in person, so a walkthrough must not name or describe internal work until that is built. A built file is owned by where its content comes from, never by who reads it, and each source is recorded as the file is written (`vite/settle.ts`): a stylesheet's CSS modules, an asset's original files, a worker's output; a file with no record and no fixed name fails the build. Nothing a prototype owns is inlined by the size limit, and nothing under `prototypes/` is ever the hub's: a file directly there, or in a folder without a README, is refused (shared code belongs in `kit/`). Any import or `new URL` (`?inline` included) into a prototype its importer does not own is refused in dev and in a build. Every stylesheet is read for reaches inside Vite's postcss run (`vite/css-boundary.ts`), each reference followed as a path and through Vite's own resolvers (aliases and package paths included); Sass, Less and Stylus are refused in prototypes and the project's `kit/`, since their imports resolve inside the preprocessor; and every worker bundle refuses a module under `prototypes/` and resolves `@kit/*`. After the bundle is settled the build reads what it wrote (`vite/leaks.ts`): a file outside `/_p/<slug>/` that holds a whole file of `prototypes/<slug>/` (its bytes, a base64 or SVG data URI of it anywhere in the file, or, for a file the build read, its whole text as a string in a script; 40 bytes or more) fails the build, unless the reader's owner has a source with the same content. It is a backstop for whole-file inlining: no part of a file (a line, a rule) is looked for. Vite is pinned to 8.3 (`~8.3.5`) because the boundary leans on its internals; `vite/build.test.ts` is what to run on a Vite upgrade. A file a prototype owns lives in its folder; the hub's and the kit's live in `/assets/` and are never copied into a prototype's folder; the same bytes from several owners become one copy per owner, each named from its owner's source. A file that reads what another prototype owns, or a hub or kit file that reads what a prototype owns, fails the build, naming both. A prototype that reaches into another (an import, a CSS `@import` or `url()`, a `new URL`) or starts a web worker fails the build. A Client asking for a prototype's page (`/<project>/<slug>/`) or anything under `/<project>/_p/<slug>/` gets 404 unless that prototype is client-facing, asked of the store on every such request; `/<project>/_p/all.js` is always 404 to a Client, and an internal prototype and one that does not exist answer byte for byte the same. Below a project, any first segment that is not the hub's own (`assets`, `api`, `guide`, `_gate`, `index.html`, `favicon.svg`), `_p` or a prototype slug gets the same 404. A path that could mean more than one file (a `.` or `..` segment, a backslash, a control character, an empty segment, a `%` left after decoding, or one that does not decode) goes nowhere for anyone, Studio included. Another client's project, and a project with no build, are the same 404, its review API too. A Client's comments on a prototype that is not client-facing answer as if it had none. Studio passes on the cookie's kind with no audience read. The client's hub at `/` and a project's `/assets/*`, `/guide/*` and review API pass on the session alone. `invite`, `api`, `_gate`, `_p`, `assets`, `guide`, `index.html` and `favicon.svg` are never a prototype's slug (`RESERVED` in `core/prototype.ts`).
|
|
88
90
|
- **Signed out**, a page gets the sign-in page (401). It has no form: it says to open the link the studio sent, that each link signs in one device and then stops working, and to ask the studio for a new one for another device. Anything else gets a plain-text 401, an anonymous `POST` included.
|
|
89
91
|
|
|
90
|
-
The studio site reads its env from the Vercel project, never committed: `GATE_SECRET`, at least 32 random characters that sign the session cookie, and the database's and file store's credentials, which `studio create` sets and copies into the studio folder's `.env` (`templates/studio/.env.example` names them). With the secret or the database missing, every host answers 503 "This site is not set up yet.", which names no command, studio or client, so a misconfigured site never serves anything open. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The signed-out page names no client. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page
|
|
92
|
+
The studio site reads its env from the Vercel project, never committed: `GATE_SECRET`, at least 32 random characters that sign the session cookie, and the database's and file store's credentials, which `studio create` sets and copies into the studio folder's `.env` (`templates/studio/.env.example` names them). With the secret or the database missing, every host answers 503 "This site is not set up yet.", which names no command, studio or client, so a misconfigured site never serves anything open. The gate pages ship a hash-based Content Security Policy with no `unsafe-inline` and no script, plus `font-src 'self'` and `img-src 'self'`, and send no referrer. They wear the hub's neutral look in Geist, so two files pass the gate without a session: `/_gate/geist.woff2` (the latin subset, emitted at that fixed path) and `/favicon.svg`. Nothing else does. Every response carries `X-Robots-Tag: noindex`, so no search engine lists the site. The signed-out page names no client. Under `design-hub dev` there is no gate; `/_gate/` previews the sign-in page, `?page=link` a link's page, `?page=used` a used one and `?page=stopped` the studio host's page for an Open that cannot start. On the studio host the used page's way in says the clients, not the prototypes.
|
|
91
93
|
|
|
92
94
|
## Comments and people
|
|
93
95
|
|
|
94
96
|
Every signed-in person can comment as themselves. The People tab lists each person with their team, kind and when their access ends, and says how links behave where Studio shares them.
|
|
95
97
|
|
|
96
|
-
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `<project>/api/review` (`server/api.ts`, reached on a studio site through its one-line `api/review.ts`, scoped by the host's client and the project the path names): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is, which client a person may act in) live once, in `core/review/`, behind a small storage port: the studio's Upstash Redis over REST, or a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person in one fixed scope. Every key is built by one function from a scope, under the prefix `hub4:`: the studio's (`studio:people`, `clients`, `hosts`, …), a client's (`c:<client>:people`, `:links`, `:projects`, …) and a project's (`c:<client>:p:<project>:comments:<prototype>`, …), so no op reaches another client's records.
|
|
98
|
+
The panel (`shell/review/`) mounts on every prototype page in its own React root, so a prototype that throws never takes it down. A comment carries the prototype, the URL, every dial panel's values (`snapshotDials`), and the element it was pinned to as a selector path with an offset; Show state reopens the URL and sets the dials back. Pins draw over their elements and below the Controls panel. The API is one endpoint, `<project>/api/review` (`server/api.ts`, reached on a studio site through its one-line `api/review.ts`, scoped by the host's client and the project the path names): queries by GET, commands by POST with a JSON body, same-origin only. The rules (who may delete, what a valid comment is, which client a person may act in) live once, in `core/review/`, behind a small storage port: the studio's database (`server/stores/`: Upstash Redis over REST, or Postgres in one table of key, field and value), or a file in `.design-hub/review.json` under `design-hub dev`, where whoever runs the server is a local Studio person in one fixed scope. Every key is built by one function from a scope, under the prefix `hub4:`: the studio's (`studio:people`, `clients`, `hosts`, …), a client's (`c:<client>:people`, `:links`, `:projects`, …) and a project's (`c:<client>:p:<project>:comments:<prototype>`, …), so no op reaches another client's records.
|
|
97
99
|
|
|
98
|
-
`design-hub dev` serves the prototypes open, with the review panel on the local store. The gate and the studio's functions are covered by `pnpm test` (`vercel/
|
|
100
|
+
`design-hub dev` serves the prototypes open, with the review panel on the local store. The gate and the studio's functions are covered by `pnpm test` (`vercel/gate.test.ts`, against an in-memory Upstash and file store, and again in `vercel/gate.postgres.test.ts` on an embedded Postgres).
|
package/core/prototype.test.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
RESERVED,
|
|
12
12
|
RESERVED_CLIENTS,
|
|
13
13
|
routeOf,
|
|
14
|
+
STUDIO_PAGE,
|
|
15
|
+
studioRouteOf,
|
|
14
16
|
} from './prototype.ts';
|
|
15
17
|
|
|
16
18
|
test('a prototype or project slug is kebab-case and never a first segment the gate answers', () => {
|
|
@@ -198,3 +200,53 @@ test('anything else on a studio host goes nowhere: odd paths, the reserved names
|
|
|
198
200
|
for (const host of ['', 'localhost', 'a b'])
|
|
199
201
|
assert.deepEqual(routeOf(host, '/rebrand/'), { host: '', kind: 'none' }, host);
|
|
200
202
|
});
|
|
203
|
+
|
|
204
|
+
test('a handoff’s claim is one path at a client host’s root; anything near it is a hub path or nothing', () => {
|
|
205
|
+
const token = 'h'.repeat(43);
|
|
206
|
+
assert.deepEqual(routeOf('acme.example.com', `/_gate/handoff/${token}`), {
|
|
207
|
+
host: 'acme.example.com',
|
|
208
|
+
kind: 'handoff',
|
|
209
|
+
token,
|
|
210
|
+
});
|
|
211
|
+
for (const path of [
|
|
212
|
+
`/_gate/handoff/${token}/`,
|
|
213
|
+
'/_gate/handoff/short',
|
|
214
|
+
'/_gate/handoff',
|
|
215
|
+
`/rebrand/_gate/handoff/${token}`,
|
|
216
|
+
])
|
|
217
|
+
assert.notEqual(routeOf('acme.example.com', path).kind, 'handoff', path);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('on the studio’s own host only its hub, its bundle, its API, a link, the gate’s assets and the handoff go anywhere', () => {
|
|
221
|
+
const token = 'l'.repeat(43);
|
|
222
|
+
const cases: [string, string][] = [
|
|
223
|
+
['/', 'page'],
|
|
224
|
+
[`/invite/${token}`, 'link'],
|
|
225
|
+
['/_gate/geist.woff2', 'asset'],
|
|
226
|
+
['/favicon.svg', 'asset'],
|
|
227
|
+
['/_studio/studio-abc.js', 'file'],
|
|
228
|
+
['/_studio/geist-latin.woff2', 'file'],
|
|
229
|
+
['/api/review', 'api'],
|
|
230
|
+
['/_gate/handoff', 'handoff'],
|
|
231
|
+
[`/_gate/proof/${token}`, 'proof'],
|
|
232
|
+
];
|
|
233
|
+
for (const [path, kind] of cases) assert.equal(studioRouteOf(path).kind, kind, path);
|
|
234
|
+
for (const path of [
|
|
235
|
+
STUDIO_PAGE,
|
|
236
|
+
'/index.html',
|
|
237
|
+
'/assets/index.js',
|
|
238
|
+
'/rebrand/',
|
|
239
|
+
'/api/files',
|
|
240
|
+
'/api/review/',
|
|
241
|
+
'/_studio',
|
|
242
|
+
'/_studio/',
|
|
243
|
+
'/_studio/.%09./x',
|
|
244
|
+
'/_studio/%2e%2e/x',
|
|
245
|
+
'/_gate/proof/x',
|
|
246
|
+
`/_gate/handoff/${token}`,
|
|
247
|
+
])
|
|
248
|
+
assert.equal(studioRouteOf(path).kind, 'none', path);
|
|
249
|
+
// A client host never reaches the studio hub's files.
|
|
250
|
+
for (const path of [STUDIO_PAGE, '/_studio/studio-abc.js'])
|
|
251
|
+
assert.equal(routeOf('acme.example.com', path).kind, 'none', path);
|
|
252
|
+
});
|
package/core/prototype.ts
CHANGED
|
@@ -109,6 +109,14 @@ const GATE_ASSETS: readonly string[] = [GATE_FONT, '/favicon.svg'];
|
|
|
109
109
|
*/
|
|
110
110
|
export const PROOF_PATH = /^\/_gate\/proof\/([\w-]{20,100})$/;
|
|
111
111
|
export const proofPath = (ask: string) => `/_gate/proof/${ask}`;
|
|
112
|
+
/**
|
|
113
|
+
* A handoff's claim, on a client's host: the studio's host sends a Studio
|
|
114
|
+
* person here with a one-time token, and the gate signs them in on this host.
|
|
115
|
+
*/
|
|
116
|
+
const HANDOFF_PATH = /^\/_gate\/handoff\/([\w-]{20,100})$/;
|
|
117
|
+
export const handoffPath = (token: string) => `/_gate/handoff/${token}`;
|
|
118
|
+
/** Where the studio hub asks for a handoff, on the studio's own host: a POST of the client and the project. */
|
|
119
|
+
export const HANDOFF_START = '/_gate/handoff';
|
|
112
120
|
/**
|
|
113
121
|
* The studio site's functions, at a client host's root: the review API, and
|
|
114
122
|
* the files function the gate rewrites a project's files to. The gate passes
|
|
@@ -121,6 +129,7 @@ const FUNCTIONS: readonly string[] = ['review', 'files'];
|
|
|
121
129
|
*
|
|
122
130
|
* - `none`: nothing; the gate's plain 404, whoever asks.
|
|
123
131
|
* - `link`: `/invite/<token>`, at the host root only.
|
|
132
|
+
* - `handoff`: `/_gate/handoff/<token>`, a handoff's claim, at the host root only.
|
|
124
133
|
* - `asset`: the gate's font and the favicon, served before sign-in.
|
|
125
134
|
* - `hub`: the client's hub page and its own files (`/`, `/index.html`, `/assets/…`, `/_gate/…`).
|
|
126
135
|
* - `api`: a function at the root (`project` null), or a project's review API, `/<project>/api/review`.
|
|
@@ -130,6 +139,7 @@ const FUNCTIONS: readonly string[] = ['review', 'files'];
|
|
|
130
139
|
export type Where =
|
|
131
140
|
| { kind: 'none' }
|
|
132
141
|
| { kind: 'link'; token: string }
|
|
142
|
+
| { kind: 'handoff'; token: string }
|
|
133
143
|
| { kind: 'asset' }
|
|
134
144
|
| { kind: 'hub' }
|
|
135
145
|
| { kind: 'api'; project: string | null }
|
|
@@ -155,6 +165,8 @@ function projectRoute(project: string, rest: string[]): Where {
|
|
|
155
165
|
function where(pathname: string): Where {
|
|
156
166
|
const linked = pathname.match(LINK_PATH);
|
|
157
167
|
if (linked) return { kind: 'link', token: linked[1] };
|
|
168
|
+
const handoff = pathname.match(HANDOFF_PATH);
|
|
169
|
+
if (handoff) return { kind: 'handoff', token: handoff[1] };
|
|
158
170
|
if (GATE_ASSETS.includes(pathname)) return { kind: 'asset' };
|
|
159
171
|
const parts = segments(pathname);
|
|
160
172
|
if (!parts) return { kind: 'none' };
|
|
@@ -167,6 +179,53 @@ function where(pathname: string): Where {
|
|
|
167
179
|
return isProjectSlug(first) ? projectRoute(first, rest) : { kind: 'none' };
|
|
168
180
|
}
|
|
169
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The studio hub's own files, which the studio site's build puts beside the
|
|
184
|
+
* client hub (studioConfig in vite/plugin.ts): its page, and its bundle under
|
|
185
|
+
* one folder. Neither is a path a client's host answers: `_studio` and
|
|
186
|
+
* `studio.html` are no project slug, so routeOf sends both nowhere.
|
|
187
|
+
*/
|
|
188
|
+
export const STUDIO_DIR = '_studio';
|
|
189
|
+
export const STUDIO_PAGE = '/studio.html';
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Where a request on the studio's own host (`studio.<apex>`) goes. Only
|
|
193
|
+
* Studio signs in here, and nothing of a client's host is answered:
|
|
194
|
+
*
|
|
195
|
+
* - `none`: nothing; the gate's plain 404.
|
|
196
|
+
* - `link`: `/invite/<token>`, a Studio person's link.
|
|
197
|
+
* - `asset`: the gate's font and the favicon, served before sign-in.
|
|
198
|
+
* - `page`: `/`, the studio hub.
|
|
199
|
+
* - `file`: the studio hub's bundle, below `/_studio/`.
|
|
200
|
+
* - `api`: `/api/review`, where the studio hub reads every client.
|
|
201
|
+
* - `handoff`: `/_gate/handoff`, where the studio hub asks to open a client.
|
|
202
|
+
* - `proof`: `/_gate/proof/<ask>`, the host proof `studio create` and
|
|
203
|
+
* `studio deploy` ask the studio's own host for, as `client add` asks a client's.
|
|
204
|
+
*/
|
|
205
|
+
export type StudioWhere =
|
|
206
|
+
| { kind: 'none' }
|
|
207
|
+
| { kind: 'link'; token: string }
|
|
208
|
+
| { kind: 'asset' }
|
|
209
|
+
| { kind: 'page' }
|
|
210
|
+
| { kind: 'file' }
|
|
211
|
+
| { kind: 'api' }
|
|
212
|
+
| { kind: 'handoff' }
|
|
213
|
+
| { kind: 'proof'; ask: string };
|
|
214
|
+
|
|
215
|
+
/** The one place a request's path on the studio's own host is read. It fails closed, as routeOf does. */
|
|
216
|
+
export function studioRouteOf(pathname: string): StudioWhere {
|
|
217
|
+
const linked = pathname.match(LINK_PATH);
|
|
218
|
+
if (linked) return { kind: 'link', token: linked[1] };
|
|
219
|
+
if (GATE_ASSETS.includes(pathname)) return { kind: 'asset' };
|
|
220
|
+
if (pathname === '/') return { kind: 'page' };
|
|
221
|
+
if (pathname === '/api/review') return { kind: 'api' };
|
|
222
|
+
if (pathname === HANDOFF_START) return { kind: 'handoff' };
|
|
223
|
+
const proof = pathname.match(PROOF_PATH);
|
|
224
|
+
if (proof) return { kind: 'proof', ask: proof[1] };
|
|
225
|
+
const parts = segments(pathname);
|
|
226
|
+
return parts && parts.length > 1 && parts[0] === STUDIO_DIR ? { kind: 'file' } : { kind: 'none' };
|
|
227
|
+
}
|
|
228
|
+
|
|
170
229
|
/**
|
|
171
230
|
* The one place a studio site reads a request's path. It fails closed: a
|
|
172
231
|
* path that could mean more than one file (`segments`) goes nowhere. Which client a host is, is the store's to say (a host may be a
|
package/core/review/model.ts
CHANGED
|
@@ -40,6 +40,17 @@ export const DEFAULT_ACCESS: Access = '3m';
|
|
|
40
40
|
* archiving a client, or adding one, takes effect on every instance within it.
|
|
41
41
|
*/
|
|
42
42
|
export const HOST_SECONDS = 60;
|
|
43
|
+
/** How long a handoff lasts: Studio opens a client from the studio's host, and the client's host claims it within this. */
|
|
44
|
+
export const HANDOFF_SECONDS = 60;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The studio's own host (`studio.<apex>`): its entry in the store's `hosts`,
|
|
48
|
+
* in place of a client's slug, and the client a session on it is signed to.
|
|
49
|
+
* Never a client's slug (RESERVED_CLIENTS), so no client host is ever it.
|
|
50
|
+
*/
|
|
51
|
+
export const STUDIO_SITE = 'studio';
|
|
52
|
+
/** What a studio site's host serves: one client, the studio's own host, or nothing. */
|
|
53
|
+
export type Site = Client | typeof STUDIO_SITE | null;
|
|
43
54
|
|
|
44
55
|
const ACCESS_MONTHS: Record<Exclude<Access, 'open'>, number> = { '3m': 3, '6m': 6 };
|
|
45
56
|
|
|
@@ -140,6 +151,15 @@ export type Project = { slug: string; client: string; name: string; build: strin
|
|
|
140
151
|
/** A one-time sign-in link, stored under the hash of its token and deleted when used. */
|
|
141
152
|
export type Link = { person: string; expiresAt: string };
|
|
142
153
|
|
|
154
|
+
/**
|
|
155
|
+
* A handoff: a Studio person, signed in on the studio's host, opening one
|
|
156
|
+
* client's hub (or one of its projects) on that client's host. Stored with
|
|
157
|
+
* the client under the hash of its token, deleted when its host claims it,
|
|
158
|
+
* good for HANDOFF_SECONDS. `project` is a project of the client with a
|
|
159
|
+
* build when it was made, or null for the client's hub.
|
|
160
|
+
*/
|
|
161
|
+
export type Handoff = { person: string; project: string | null; expiresAt: string };
|
|
162
|
+
|
|
143
163
|
/** A comment's author as it was when they wrote it, so a revoked person's comments still read. */
|
|
144
164
|
export type Author = Pick<Person, 'id' | 'name' | 'team'>;
|
|
145
165
|
|