@milesroxas/design-hub 0.13.0 → 0.14.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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/core/prototype.test.ts +12 -1
  3. package/core/prototype.ts +21 -2
  4. package/core/review/model.ts +71 -6
  5. package/core/review/service.test.ts +536 -1
  6. package/core/review/service.ts +452 -25
  7. package/core/review/store.ts +45 -4
  8. package/dist/core/prototype.d.ts +20 -2
  9. package/dist/core/prototype.js +17 -2
  10. package/dist/core/review/model.d.ts +42 -3
  11. package/dist/core/review/model.js +52 -3
  12. package/dist/core/review/service.d.ts +81 -7
  13. package/dist/core/review/service.js +407 -23
  14. package/dist/core/review/store.d.ts +29 -2
  15. package/dist/core/review/store.js +4 -0
  16. package/dist/scripts/client.d.ts +1 -1
  17. package/dist/scripts/client.js +1 -1
  18. package/dist/scripts/lib/dns.d.ts +16 -2
  19. package/dist/scripts/lib/dns.js +66 -3
  20. package/dist/scripts/lib/fake-host.d.ts +16 -1
  21. package/dist/scripts/lib/fake-host.js +36 -1
  22. package/dist/scripts/lib/host.d.ts +2 -0
  23. package/dist/scripts/lib/resend.d.ts +36 -0
  24. package/dist/scripts/lib/resend.js +66 -0
  25. package/dist/scripts/lib/studio-deps.d.ts +7 -0
  26. package/dist/scripts/lib/studio-deps.js +6 -1
  27. package/dist/scripts/lib/studios.d.ts +2 -2
  28. package/dist/scripts/lib/studios.js +5 -5
  29. package/dist/scripts/lib/vercel-host.js +6 -0
  30. package/dist/scripts/people.d.ts +16 -4
  31. package/dist/scripts/people.js +67 -17
  32. package/dist/scripts/studio.d.ts +19 -3
  33. package/dist/scripts/studio.js +327 -6
  34. package/dist/server/api.d.ts +14 -2
  35. package/dist/server/api.js +71 -17
  36. package/dist/server/dev.js +21 -1
  37. package/dist/server/gate.d.ts +26 -3
  38. package/dist/server/gate.js +323 -52
  39. package/dist/server/mailer.d.ts +60 -0
  40. package/dist/server/mailer.js +104 -0
  41. package/dist/server/mailers/fake.d.ts +8 -0
  42. package/dist/server/mailers/fake.js +16 -0
  43. package/dist/server/mailers/resend.d.ts +21 -0
  44. package/dist/server/mailers/resend.js +49 -0
  45. package/dist/server/session.js +4 -1
  46. package/dist/vercel/proxy.js +10 -3
  47. package/dist/vite/plugin.js +3 -1
  48. package/kit/ui/Menu.tsx +29 -18
  49. package/kit/ui/layer.ts +41 -0
  50. package/package.json +1 -1
  51. package/shell/review/Bar.tsx +1 -0
  52. package/shell/review/Card.tsx +17 -7
  53. package/shell/review/People.tsx +908 -134
  54. package/shell/review/Review.tsx +2 -2
  55. package/shell/review/anchor.ts +6 -1
  56. package/shell/review/client.ts +41 -7
  57. package/shell/review/menu-place.test.ts +41 -0
  58. package/shell/review/place.test.ts +26 -1
  59. package/shell/review/place.ts +17 -0
  60. package/shell/review/review.css +97 -11
  61. package/shell/review/view.test.ts +115 -1
  62. package/shell/review/view.ts +92 -2
  63. package/shell/studio/StudioHub.tsx +1 -0
  64. package/shell/studio/hub.css +99 -13
  65. package/skills/miles-deploy/SKILL.md +24 -3
  66. package/templates/studio/.env.example +6 -0
  67. package/templates/studio/package.json +1 -1
package/README.md CHANGED
@@ -87,7 +87,7 @@ Every person is named, and signs in with a one-time link that Studio makes in th
87
87
  - **The session** is one cookie, `__Host-hub_person`: `HttpOnly`, `Secure`, `SameSite=Lax`, host-only. Its token is `p5.<id>.<epoch>.<kind>.<client>.<expires>.<checkedAt>.<sig>`, signed with HMAC-SHA256 over all of those and over two things it never carries: the review store's URL, so two studios that share a `GATE_SECRET` never accept each other's cookies, and when the client was added, so a slug archived and added again accepts no token from before. A token verifies only on its own client's host, a Studio person's too. Any other version never verifies. It lasts to the access end, at most 400 days, the longest a browser keeps one. For `CHECK_SECONDS` (5 minutes) after `checkedAt` any request passes on the signature. After that the next request, of any kind, asks the store: a current person passes with a fresh cookie whose expiry follows their current access end; a revoked, signed-out-everywhere or ended person gets 401 and the cookie cleared. The request's own headers never decide whether the store is asked, since the client chooses them. A store that fails answers 503 with `Retry-After`, and leaves the cookie, so an outage signs nobody out; the review panel reads `Retry-After` as try again. The API function answers the same way in JSON. The sign-in POST also refuses a store failure with 503, and a link is checked before it is used up, so a failure never burns one. The hub reads any 401, the gate's plain text or the API's JSON, as signed out.
88
88
  - **The link page** sends `Referrer-Policy: same-origin`, so Continue's POST carries a real `Origin` (with `no-referrer` a browser sends `Origin: null`, trusted only beside `Sec-Fetch-Site`, which older Safari does not send). Every other gate response sends `no-referrer`.
89
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`).
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.
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 works once, on one device, and to ask the studio for a new one. Anything else gets a plain-text 401, an anonymous `POST` included.
91
91
 
92
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.
93
93
 
@@ -33,7 +33,8 @@ test('a prototype or project slug is kebab-case and never a first segment the ga
33
33
  });
34
34
 
35
35
  test('a client slug is kebab-case and never the studio’s own host names', () => {
36
- assert.deepEqual([...RESERVED_CLIENTS], ['studio', 'www', 'api']);
36
+ // `mail` too: the default sender's subdomain (email.md, E11).
37
+ assert.deepEqual([...RESERVED_CLIENTS], ['studio', 'www', 'api', 'mail']);
37
38
  for (const reserved of RESERVED_CLIENTS) assert.equal(isClientSlug(reserved), false, reserved);
38
39
  assert.equal(isClientSlug('acme'), true);
39
40
  // A prototype's reserved names are no concern of a host's.
@@ -143,6 +144,11 @@ test('a studio path goes to the link, the gate’s assets, the client’s hub, a
143
144
  for (const path of ['/api/review', '/api/files'])
144
145
  assert.deepEqual(route(path), { kind: 'api', project: null }, path);
145
146
  assert.deepEqual(route('/rebrand/api/review'), { kind: 'api', project: 'rebrand' });
147
+ // Email sign-in's two paths, exactly; anything near them is the hub's, as before.
148
+ assert.deepEqual(route('/_gate/code'), { kind: 'code', step: 'ask' });
149
+ assert.deepEqual(route('/_gate/code/use'), { kind: 'code', step: 'use' });
150
+ for (const path of ['/_gate/code/', '/_gate/code/use/', '/_gate/code/other'])
151
+ assert.deepEqual(route(path), { kind: 'hub' }, path);
146
152
  assert.deepEqual(route('/rebrand/'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
147
153
  assert.deepEqual(route('/rebrand'), { kind: 'file', project: 'rebrand', file: [], prototype: null });
148
154
  assert.deepEqual(route('/rebrand/assets/index-x.js'), {
@@ -229,8 +235,11 @@ test('on the studio’s own host only its hub, its bundle, its API, a link, the
229
235
  ['/api/review', 'api'],
230
236
  ['/_gate/handoff', 'handoff'],
231
237
  [`/_gate/proof/${token}`, 'proof'],
238
+ ['/_gate/code', 'code'],
239
+ ['/_gate/code/use', 'code'],
232
240
  ];
233
241
  for (const [path, kind] of cases) assert.equal(studioRouteOf(path).kind, kind, path);
242
+ assert.deepEqual(studioRouteOf('/_gate/code/use'), { kind: 'code', step: 'use' });
234
243
  for (const path of [
235
244
  STUDIO_PAGE,
236
245
  '/index.html',
@@ -244,6 +253,8 @@ test('on the studio’s own host only its hub, its bundle, its API, a link, the
244
253
  '/_studio/%2e%2e/x',
245
254
  '/_gate/proof/x',
246
255
  `/_gate/handoff/${token}`,
256
+ '/_gate/code/',
257
+ '/_gate/code/other',
247
258
  ])
248
259
  assert.equal(studioRouteOf(path).kind, 'none', path);
249
260
  // A client host never reaches the studio hub's files.
package/core/prototype.ts CHANGED
@@ -19,8 +19,8 @@ export const RESERVED = [
19
19
  'favicon.svg',
20
20
  ] as const;
21
21
 
22
- /** Never a client's slug: the studio's own host, and the names a host is often given. */
23
- export const RESERVED_CLIENTS = ['studio', 'www', 'api'] as const;
22
+ /** Never a client's slug: the studio's own host, the names a host is often given, and `mail`, the default sender's subdomain (email.md, E11). */
23
+ export const RESERVED_CLIENTS = ['studio', 'www', 'api', 'mail'] as const;
24
24
 
25
25
  /**
26
26
  * Everything built from `prototypes/<slug>/` lands under `/_p/<slug>/`, and
@@ -117,6 +117,17 @@ const HANDOFF_PATH = /^\/_gate\/handoff\/([\w-]{20,100})$/;
117
117
  export const handoffPath = (token: string) => `/_gate/handoff/${token}`;
118
118
  /** Where the studio hub asks for a handoff, on the studio's own host: a POST of the client and the project. */
119
119
  export const HANDOFF_START = '/_gate/handoff';
120
+ /**
121
+ * Email sign-in, on a client's host and on the studio's (email.md): a POST of
122
+ * an address asks for a code, a POST of the code uses it. The gate answers
123
+ * them only when the studio has a mailer; otherwise each is what any other
124
+ * path there is.
125
+ */
126
+ export const CODE_ASK = '/_gate/code';
127
+ export const CODE_USE = '/_gate/code/use';
128
+ type CodeStep = 'ask' | 'use';
129
+ const codeStep = (pathname: string): CodeStep | null =>
130
+ pathname === CODE_ASK ? 'ask' : pathname === CODE_USE ? 'use' : null;
120
131
  /**
121
132
  * The studio site's functions, at a client host's root: the review API, and
122
133
  * the files function the gate rewrites a project's files to. The gate passes
@@ -131,6 +142,7 @@ const FUNCTIONS: readonly string[] = ['review', 'files'];
131
142
  * - `link`: `/invite/<token>`, at the host root only.
132
143
  * - `handoff`: `/_gate/handoff/<token>`, a handoff's claim, at the host root only.
133
144
  * - `asset`: the gate's font and the favicon, served before sign-in.
145
+ * - `code`: `/_gate/code` and `/_gate/code/use`, email sign-in, when the studio has a mailer.
134
146
  * - `hub`: the client's hub page and its own files (`/`, `/index.html`, `/assets/…`, `/_gate/…`).
135
147
  * - `api`: a function at the root (`project` null), or a project's review API, `/<project>/api/review`.
136
148
  * - `file`: a file of a project's build, as its segments ([] for the project's own page), and
@@ -141,6 +153,7 @@ export type Where =
141
153
  | { kind: 'link'; token: string }
142
154
  | { kind: 'handoff'; token: string }
143
155
  | { kind: 'asset' }
156
+ | { kind: 'code'; step: CodeStep }
144
157
  | { kind: 'hub' }
145
158
  | { kind: 'api'; project: string | null }
146
159
  | { kind: 'file'; project: string; file: string[]; prototype: string | null };
@@ -168,6 +181,8 @@ function where(pathname: string): Where {
168
181
  const handoff = pathname.match(HANDOFF_PATH);
169
182
  if (handoff) return { kind: 'handoff', token: handoff[1] };
170
183
  if (GATE_ASSETS.includes(pathname)) return { kind: 'asset' };
184
+ const step = codeStep(pathname);
185
+ if (step) return { kind: 'code', step };
171
186
  const parts = segments(pathname);
172
187
  if (!parts) return { kind: 'none' };
173
188
  const [first, ...rest] = parts;
@@ -199,6 +214,7 @@ export const STUDIO_PAGE = '/studio.html';
199
214
  * - `file`: the studio hub's bundle, below `/_studio/`.
200
215
  * - `api`: `/api/review`, where the studio hub reads every client.
201
216
  * - `handoff`: `/_gate/handoff`, where the studio hub asks to open a client.
217
+ * - `code`: `/_gate/code` and `/_gate/code/use`, a Studio person's email sign-in.
202
218
  * - `proof`: `/_gate/proof/<ask>`, the host proof `studio create` and
203
219
  * `studio deploy` ask the studio's own host for, as `client add` asks a client's.
204
220
  */
@@ -210,6 +226,7 @@ export type StudioWhere =
210
226
  | { kind: 'file' }
211
227
  | { kind: 'api' }
212
228
  | { kind: 'handoff' }
229
+ | { kind: 'code'; step: CodeStep }
213
230
  | { kind: 'proof'; ask: string };
214
231
 
215
232
  /** The one place a request's path on the studio's own host is read. It fails closed, as routeOf does. */
@@ -220,6 +237,8 @@ export function studioRouteOf(pathname: string): StudioWhere {
220
237
  if (pathname === '/') return { kind: 'page' };
221
238
  if (pathname === '/api/review') return { kind: 'api' };
222
239
  if (pathname === HANDOFF_START) return { kind: 'handoff' };
240
+ const step = codeStep(pathname);
241
+ if (step) return { kind: 'code', step };
223
242
  const proof = pathname.match(PROOF_PATH);
224
243
  if (proof) return { kind: 'proof', ask: proof[1] };
225
244
  const parts = segments(pathname);
@@ -89,7 +89,12 @@ export type Person = {
89
89
  * client. Never stored in the profile: it is where the person's records live.
90
90
  */
91
91
  client: string | null;
92
- /** Always null until email sign-in exists. */
92
+ /**
93
+ * The address they sign in with by code (lower case, trimmed), or null for
94
+ * links only. Within one client's people, or the studio's own, one live
95
+ * person holds an address (`emails` in store.ts). A profile stored before
96
+ * email existed reads as null.
97
+ */
93
98
  email: string | null;
94
99
  /** When their access ends (ISO time), or null for open-ended. Their sessions end with it. */
95
100
  accessEndsAt: string | null;
@@ -151,6 +156,17 @@ export type Project = { slug: string; client: string; name: string; build: strin
151
156
  /** A one-time sign-in link, stored under the hash of its token and deleted when used. */
152
157
  export type Link = { person: string; expiresAt: string };
153
158
 
159
+ /**
160
+ * A person's one live sign-in code (`codes` in store.ts): an HMAC of the code
161
+ * under a key the service is given, never the code or a bare digest, since
162
+ * 8 digits can be tried in full. A new code replaces it; a right answer
163
+ * removes it.
164
+ */
165
+ export type Code = { hash: string; expiresAt: string; sentAt: string };
166
+
167
+ /** The code rules (E6): 8 digits, 10 minutes, 5 wrong tries, one a minute and 5 an hour per person. */
168
+ export const CODE = { digits: 8, minutes: 10, tries: 5, gapSeconds: 60, perHour: 5 } as const;
169
+
154
170
  /**
155
171
  * A handoff: a Studio person, signed in on the studio's host, opening one
156
172
  * client's hub (or one of its projects) on that client's host. Stored with
@@ -239,7 +255,8 @@ const PROFILE_RULES: [string, (v: unknown) => boolean][] = [
239
255
  ['name', isText],
240
256
  ['team', isText],
241
257
  ['kind', (v) => PERSON_KINDS.includes(v as PersonKind)],
242
- ['email', isTextOrNull],
258
+ // Absent on a profile stored before email existed: it reads as null (no migration).
259
+ ['email', (v) => v === undefined || isTextOrNull(v)],
243
260
  ['accessEndsAt', isTextOrNull],
244
261
  ['createdAt', isText],
245
262
  ];
@@ -273,6 +290,12 @@ export const isRoot = (c: Comment) => c.thread === c.id;
273
290
 
274
291
  export type Checked<T> = { ok: true; value: T } | { ok: false; problems: string[] };
275
292
 
293
+ /** What a refusal says when it names fields only: the panel then shows the fields' problems. */
294
+ export const NOT_VALID = 'Some fields are not valid.';
295
+ /** What a refusal says when an address is the one thing wrong, so a person reads a sentence, not a field. */
296
+ export const NOT_AN_EMAIL =
297
+ 'That is not an email address. Use one such as name@example.com, or leave it empty.';
298
+
276
299
  const text = (v: unknown, path: string, max: number, problems: string[]): string => {
277
300
  if (typeof v !== 'string' || !v.trim()) {
278
301
  problems.push(`${path}: required`);
@@ -293,13 +316,39 @@ export function checkAccess(input: unknown): Checked<Access> {
293
316
  return isAccess(input) ? { ok: true, value: input } : { ok: false, problems: [ACCESS_PROBLEM] };
294
317
  }
295
318
 
296
- /** `team` absent: the service fills it, the studio's name for Studio and the client's for a Client. */
297
- export type PersonInput = Pick<Person, 'name' | 'kind'> & { team?: string; access: Access | null };
319
+ /**
320
+ * What an address may be: the form a browser's email field takes (WHATWG),
321
+ * lower case, 254 characters at most. Nothing in it can split a mail header
322
+ * or name a second recipient: no space, comma, semicolon, angle bracket or quote.
323
+ */
324
+ const EMAIL =
325
+ /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
326
+ const EMAIL_MAX = 254;
327
+ export const EMAIL_PROBLEM = 'email: an address such as name@example.com, or empty for links only';
328
+
329
+ /** An address as stored: trimmed and lower case, or null when it is not one. */
330
+ export function emailOf(input: unknown): string | null {
331
+ if (typeof input !== 'string') return null;
332
+ const address = input.trim().toLowerCase();
333
+ return address.length <= EMAIL_MAX && EMAIL.test(address) ? address : null;
334
+ }
335
+
336
+ /** An address as Studio sets it: null, or empty, is links only; anything else must be an address. */
337
+ export function checkEmail(input: unknown): Checked<string | null> {
338
+ if (input === null || (typeof input === 'string' && input.trim() === '')) return { ok: true, value: null };
339
+ const address = emailOf(input);
340
+ return address ? { ok: true, value: address } : { ok: false, problems: [EMAIL_PROBLEM] };
341
+ }
342
+
343
+ /** `team` absent: the service fills it, the studio's name for Studio and the client's for a Client. `email` absent is links only. */
344
+ export type PersonInput = Pick<Person, 'name' | 'kind' | 'email'> & { team?: string; access: Access | null };
298
345
 
299
346
  export function checkPersonInput(input: unknown): Checked<PersonInput> {
300
347
  const i = (input ?? {}) as Record<string, unknown>;
301
348
  const problems: string[] = [];
302
349
  const name = text(i.name, 'name', LIMITS.name, problems);
350
+ const email = checkEmail(i.email ?? null);
351
+ if (!email.ok) problems.push(...email.problems);
303
352
  const team = i.team === undefined ? undefined : text(i.team, 'team', LIMITS.team, problems);
304
353
  // Most people added are on the client's side; Studio is the deliberate choice.
305
354
  const kind = i.kind ?? 'client';
@@ -315,6 +364,7 @@ export function checkPersonInput(input: unknown): Checked<PersonInput> {
315
364
  name,
316
365
  ...(team === undefined ? {} : { team }),
317
366
  kind: kind as PersonKind,
367
+ email: email.ok ? email.value : null,
318
368
  access: access as Access | null,
319
369
  },
320
370
  };
@@ -430,14 +480,29 @@ const isSlug = (v: unknown) => typeof v === 'string' && SLUG.test(v);
430
480
  const isObject = (v: unknown): v is Record<string, unknown> =>
431
481
  !!v && typeof v === 'object' && !Array.isArray(v);
432
482
 
483
+ const PATH_BASE = 'https://path.invalid';
484
+ /**
485
+ * A path on the page's own site. Starting with `/` is not enough: a browser
486
+ * reads `//host`, `/\host` and `/<tab>/host` as another site, so the path is
487
+ * resolved the way a browser would and must stay on the same origin.
488
+ */
489
+ export function isSitePath(v: unknown): v is string {
490
+ if (typeof v !== 'string' || !v.startsWith('/')) return false;
491
+ try {
492
+ return new URL(v, PATH_BASE).origin === PATH_BASE;
493
+ } catch {
494
+ return false;
495
+ }
496
+ }
497
+
433
498
  /** One rule per field: the field, whether a value passes, and what the field must be. */
434
499
  const ANCHOR_RULES: [keyof Anchor, (v: unknown) => boolean, string][] = [
435
500
  ['prototype', isSlug, 'a prototype slug'],
436
501
  ['feature', (v) => v === '' || isSlug(v), 'a feature slug or empty'],
437
502
  [
438
503
  'url',
439
- (v) => typeof v === 'string' && v.startsWith('/') && v.length <= LIMITS.url,
440
- `a path starting with /, ${LIMITS.url} characters at most`,
504
+ (v) => isSitePath(v) && v.length <= LIMITS.url,
505
+ `a path on this site starting with /, ${LIMITS.url} characters at most`,
441
506
  ],
442
507
  [
443
508
  'dials',