@milesroxas/design-hub 0.6.1 → 0.7.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 (55) hide show
  1. package/README.md +17 -7
  2. package/core/review/model.ts +90 -10
  3. package/core/review/policy.test.ts +62 -0
  4. package/core/review/policy.ts +13 -9
  5. package/core/review/service.test.ts +464 -54
  6. package/core/review/service.ts +168 -36
  7. package/core/review/store.ts +31 -7
  8. package/dist/core/review/model.d.ts +39 -7
  9. package/dist/core/review/model.js +73 -7
  10. package/dist/core/review/policy.d.ts +4 -1
  11. package/dist/core/review/policy.js +4 -4
  12. package/dist/core/review/service.d.ts +24 -6
  13. package/dist/core/review/service.js +155 -36
  14. package/dist/core/review/store.d.ts +15 -5
  15. package/dist/core/review/store.js +27 -6
  16. package/dist/scripts/bootstrap.d.ts +16 -14
  17. package/dist/scripts/bootstrap.js +56 -39
  18. package/dist/scripts/lib/deploy.d.ts +12 -4
  19. package/dist/scripts/lib/deploy.js +47 -13
  20. package/dist/scripts/lib/review.js +3 -3
  21. package/dist/scripts/lib/vercel.d.ts +8 -2
  22. package/dist/scripts/lib/vercel.js +23 -9
  23. package/dist/scripts/people.d.ts +16 -29
  24. package/dist/scripts/people.js +72 -39
  25. package/dist/scripts/preflight.js +2 -2
  26. package/dist/scripts/share.d.ts +2 -3
  27. package/dist/scripts/share.js +18 -10
  28. package/dist/server/api.d.ts +6 -2
  29. package/dist/server/api.js +53 -22
  30. package/dist/server/dev.js +3 -3
  31. package/dist/server/fake-upstash.js +3 -2
  32. package/dist/server/local.d.ts +2 -2
  33. package/dist/server/local.js +6 -4
  34. package/dist/server/session.d.ts +25 -10
  35. package/dist/server/session.js +69 -52
  36. package/dist/server/upstash.js +4 -3
  37. package/dist/vercel/proxy.d.ts +5 -3
  38. package/dist/vercel/proxy.js +183 -157
  39. package/dist/vite/plugin.js +5 -5
  40. package/kit/ui/Menu.tsx +14 -4
  41. package/kit/ui/ui.css +16 -3
  42. package/package.json +2 -2
  43. package/shell/review/Bar.tsx +5 -4
  44. package/shell/review/People.tsx +194 -55
  45. package/shell/review/Review.tsx +9 -8
  46. package/shell/review/ThreadCard.tsx +24 -21
  47. package/shell/review/client.ts +37 -18
  48. package/shell/review/review.css +9 -1
  49. package/skills/miles-deploy/SKILL.md +44 -16
  50. package/skills/miles-design-hub/SKILL.md +5 -5
  51. package/skills/miles-new-feature/SKILL.md +1 -1
  52. package/skills/miles-review/SKILL.md +7 -5
  53. package/skills/miles-worktrees/SKILL.md +1 -1
  54. package/templates/conductor/settings.toml +1 -1
  55. package/templates/guide.md +1 -1
@@ -1,84 +1,59 @@
1
1
  // Vercel Routing Middleware (the project's proxy.ts, named in vercel.json as
2
2
  // proxy.entrypoint): the gate in front of every path of the deployed
3
- // prototypes, the review API included.
4
- // Two ways in, both signed cookies (server/session.ts):
3
+ // prototypes, the review API included. There is one way in, a one-time link
4
+ // that Studio makes for one named person:
5
5
  //
6
- // the shared password view only; the form posts back to the same URL and
7
- // keeps the hash through the redirect
8
- // an invite link /invite/<token> signs one person in, to comment as
9
- // themselves; a revoke or reissue ends it on their
10
- // next page load
6
+ // GET /invite/<token> shows who the link is for, and uses nothing up, so
7
+ // a mail or chat preview that opens it costs nothing
8
+ // POST /invite/<token> uses the link up, sets the person's signed cookie
9
+ // (server/session.ts) and goes to the hub
11
10
  //
12
- // With GATE_PASSWORD or GATE_SECRET missing the gate fails closed (503).
11
+ // A used, expired or unknown link is 404. Every other path needs the cookie.
12
+ // It carries when the store last said yes; after CHECK_SECONDS (5 minutes)
13
+ // the gate asks the store again on the next request of any kind, so a revoke,
14
+ // a sign out everywhere or a changed access end reaches every request within
15
+ // minutes. A store that does not answer is 503, never a sign out. Without a session a
16
+ // page gets the sign-in page (401), which says what to do and has no form,
17
+ // and anything else a plain-text 401. Without GATE_SECRET the gate fails
18
+ // closed (503).
13
19
  import { next } from '@vercel/functions';
14
20
  import { base64, sha256 } from '../core/bytes.js';
15
21
  import { escapeHtml } from '../core/html.js';
16
22
  import { deployedReview } from '../server/api.js';
17
- import { clearedCookie, GATE_COOKIE, gateTokenIsValid, issueGateToken, issuePersonToken, PERSON_COOKIE, passwordMatches, readCookie, readGate, readPersonToken, sameOrigin, sessionCookie, } from '../server/session.js';
23
+ import { clearedCookie, isFresh, issuePersonToken, PERSON_COOKIE, readCookie, readGate, readPersonToken, sameOrigin, sessionCookie, sessionSeconds, } from '../server/session.js';
18
24
  const DEFAULT_SITE_NAME = 'Prototypes';
19
- const WRONG_PASSWORD_DELAY_MS = 800;
20
- const MAX_PASSWORD_LENGTH = 256;
21
- const INVITE_PATH = /^\/invite\/([\w-]{20,100})\/?$/;
22
- // What the gate page itself loads, served before sign-in: the hub's face
23
- // (the Vite plugin emits it at this fixed path) and the favicon. Nothing else.
25
+ const LINK_PATH = /^\/invite\/([\w-]{20,100})\/?$/;
26
+ // What the gate pages load before sign-in: the hub's face (the Vite plugin
27
+ // emits it at this fixed path) and the favicon. Nothing else.
24
28
  export const GATE_FONT = '/_gate/geist.woff2';
25
29
  const GATE_ASSETS = new Set([GATE_FONT, '/favicon.svg']);
26
- // The gate page. CSS and JS are constants so their CSP hashes can be computed
27
- // once and the page carries no 'unsafe-inline'. The gate is hub chrome, so it
28
- // wears the hub's neutral system look (shell/system.css) inlined, never the
29
- // project's brand. Geist (latin, variable) is the one font, preloaded so the
30
- // first paint is already in it.
30
+ // The gate pages. The CSS is a constant so its CSP hash is computed once and
31
+ // the pages carry no 'unsafe-inline', and they run no script at all. The gate
32
+ // is hub chrome, so it wears the hub's neutral system look (shell/system.css)
33
+ // inlined, never the project's brand. Geist (latin, variable) is the one
34
+ // font, preloaded so the first paint is already in it.
31
35
  const CSS = `
32
36
  @font-face{font-family:Geist;src:url(${GATE_FONT}) format("woff2");font-weight:100 900;font-style:normal;font-display:swap}
33
- :root{color-scheme:light;--bg:oklch(.985 0 0);--surface:oklch(1 0 0);--ink:oklch(.205 0 0);--ink-2:oklch(.371 0 0);--ink-3:oklch(.46 0 0);--ink-4:oklch(.54 0 0);--line:oklch(.87 0 0);--fill-hover:oklch(.97 0 0);--brand:oklch(.205 0 0);--brand-hover:oklch(.3 0 0);--on-brand:oklch(.985 0 0);--error:oklch(.505 .213 27.518);--error-line:oklch(.637 .237 25.331);--ring:0 0 0 2px oklch(1 0 0),0 0 0 4px oklch(.556 0 0);--ring-error:0 0 0 2px oklch(1 0 0),0 0 0 4px oklch(.637 .237 25.331);--shadow:0 1px 2px 0 oklch(0 0 0/.05);--raised:0 0 0 1px oklch(0 0 0/.06),0 1px 2px oklch(0 0 0/.05),0 12px 24px -8px oklch(0 0 0/.1);--ease-out:cubic-bezier(.23,1,.32,1);--ease-press:cubic-bezier(.33,1,.68,1);--ease-hover:cubic-bezier(.25,.46,.45,.94)}
34
- @media(prefers-color-scheme:dark){:root{color-scheme:dark;--bg:oklch(.145 0 0);--surface:oklch(.175 0 0);--ink:oklch(.985 0 0);--ink-2:oklch(.87 0 0);--ink-3:oklch(.72 0 0);--ink-4:oklch(.66 0 0);--line:oklch(.32 0 0);--fill-hover:oklch(.215 0 0);--brand:oklch(.985 0 0);--brand-hover:oklch(.87 0 0);--on-brand:oklch(.205 0 0);--error:oklch(.704 .191 22.216);--error-line:oklch(.704 .191 22.216);--ring:0 0 0 2px oklch(.175 0 0),0 0 0 4px oklch(.708 0 0);--ring-error:0 0 0 2px oklch(.175 0 0),0 0 0 4px oklch(.704 .191 22.216);--shadow:0 0 #0000;--raised:0 0 0 1px oklch(1 0 0/.09)}}
37
+ :root{color-scheme:light;--bg:oklch(.985 0 0);--surface:oklch(1 0 0);--ink:oklch(.205 0 0);--ink-3:oklch(.46 0 0);--brand:oklch(.205 0 0);--brand-hover:oklch(.3 0 0);--on-brand:oklch(.985 0 0);--ring:0 0 0 2px oklch(1 0 0),0 0 0 4px oklch(.556 0 0);--shadow:0 1px 2px 0 oklch(0 0 0/.05);--raised:0 0 0 1px oklch(0 0 0/.06),0 1px 2px oklch(0 0 0/.05),0 12px 24px -8px oklch(0 0 0/.1);--ease-out:cubic-bezier(.23,1,.32,1);--ease-press:cubic-bezier(.33,1,.68,1);--ease-hover:cubic-bezier(.25,.46,.45,.94)}
38
+ @media(prefers-color-scheme:dark){:root{color-scheme:dark;--bg:oklch(.145 0 0);--surface:oklch(.175 0 0);--ink:oklch(.985 0 0);--ink-3:oklch(.72 0 0);--brand:oklch(.985 0 0);--brand-hover:oklch(.87 0 0);--on-brand:oklch(.205 0 0);--ring:0 0 0 2px oklch(.175 0 0),0 0 0 4px oklch(.708 0 0);--shadow:0 0 #0000;--raised:0 0 0 1px oklch(1 0 0/.09)}}
35
39
  *{box-sizing:border-box}
36
40
  html{height:100%;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}
37
41
  body{margin:0;min-height:100%;display:grid;place-items:center;padding:max(24px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));background:var(--bg);color:var(--ink);font:14px/20px Geist,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;font-optical-sizing:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}
38
- [hidden]{display:none!important}
39
42
  .gate{width:100%;max-width:360px;padding:32px;background:var(--surface);border-radius:12px;box-shadow:var(--raised);transition:opacity 240ms var(--ease-out),transform 240ms var(--ease-out)}
40
43
  @starting-style{.gate{opacity:0;transform:translateY(6px)}}
41
44
  h1{margin:0 0 4px;font-size:20px;line-height:28px;font-weight:600;letter-spacing:-.02em;text-wrap:balance}
42
- .hint{margin:0 0 24px;color:var(--ink-3);text-wrap:pretty}
43
- .hint strong{font-weight:500;color:var(--ink)}
44
- label{display:block;margin-bottom:6px;font-weight:500;color:var(--ink-2)}
45
- .field{position:relative}
46
- input{display:block;width:100%;height:40px;padding:0 44px 0 12px;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--ink);box-shadow:var(--shadow);font:inherit;transition:border-color 120ms var(--ease-hover),box-shadow 120ms var(--ease-hover)}
47
- input:focus-visible{outline:2px solid transparent;outline-offset:2px;box-shadow:var(--ring),var(--shadow)}
48
- input[aria-invalid=true]{border-color:var(--error-line)}
49
- input[aria-invalid=true]:focus-visible{box-shadow:var(--ring-error),var(--shadow)}
50
- .toggle{position:absolute;top:4px;right:4px;width:32px;height:32px;display:grid;place-items:center;margin:0;padding:0;border:0;border-radius:2px;background:transparent;color:var(--ink-4);cursor:pointer;touch-action:manipulation;-webkit-user-select:none;user-select:none;transition:color 120ms var(--ease-hover),background-color 120ms var(--ease-hover)}
51
- .toggle::before{content:"";position:absolute;inset:-4px}
52
- .toggle svg{display:block}
53
- .toggle:focus-visible{outline:2px solid transparent;box-shadow:var(--ring)}
54
- .toggle:active{color:var(--ink-2)}
55
- .toggle[aria-pressed=true] .show,.toggle[aria-pressed=false] .hide{display:none}
56
- @media(hover:hover) and (pointer:fine){.toggle:hover{color:var(--ink-2);background:var(--fill-hover)}}
57
- .note{margin:8px 0 0;color:var(--ink-3)}
58
- .error{color:var(--error)}
59
- .go{display:block;width:100%;height:44px;margin-top:20px;border:0;border-radius:6px;background:var(--brand);color:var(--on-brand);font:inherit;font-weight:500;cursor:pointer;touch-action:manipulation;-webkit-user-select:none;user-select:none;box-shadow:var(--shadow);transition:background-color 120ms var(--ease-hover),transform 160ms var(--ease-press),opacity 120ms var(--ease-hover)}
45
+ p{margin:0;color:var(--ink-3);text-wrap:pretty}
46
+ p+p{margin-top:8px}
47
+ strong{font-weight:500;color:var(--ink)}
48
+ form{margin:0}
49
+ .go{display:block;width:100%;height:44px;margin-top:24px;padding:0;border:0;border-radius:6px;background:var(--brand);color:var(--on-brand);font:inherit;font-weight:500;line-height:44px;text-align:center;text-decoration:none;cursor:pointer;touch-action:manipulation;-webkit-user-select:none;user-select:none;box-shadow:var(--shadow);transition:background-color 120ms var(--ease-hover),transform 160ms var(--ease-press)}
60
50
  .go:focus-visible{outline:2px solid transparent;outline-offset:2px;box-shadow:var(--ring)}
61
51
  .go:active{transform:scale(.97)}
62
- form[data-busy] .go{opacity:.7;pointer-events:none}
63
52
  @media(hover:hover) and (pointer:fine){.go:hover{background:var(--brand-hover)}}
64
- @media(pointer:coarse){input{height:44px;font-size:16px}.toggle{width:36px;height:36px}}
65
53
  @media(max-width:400px){.gate{padding:24px}}
66
54
  @media(prefers-reduced-motion:reduce){.gate{transition:opacity 240ms var(--ease-out)}@starting-style{.gate{transform:none}}.go:active{transform:none}}
67
55
  `;
68
- // Keeps the hash route the visitor asked for (a form posts to its action
69
- // without the fragment), shows the password on request, and says when Caps
70
- // Lock is on. The toggle swallows pointerdown so the caret stays in the field.
71
- const JS = `var f=document.forms[0],p=document.getElementById('password'),t=document.getElementById('toggle'),c=document.getElementById('caps');
72
- if(location.hash){f.action=location.pathname+location.search+location.hash}
73
- t.addEventListener('pointerdown',function(e){e.preventDefault()});
74
- t.addEventListener('click',function(){var s=p.type==='password';p.type=s?'text':'password';t.setAttribute('aria-pressed',s);t.setAttribute('aria-label',s?'Hide password':'Show password')});
75
- function caps(e){if(e.getModifierState){c.hidden=!e.getModifierState('CapsLock')}}
76
- p.addEventListener('keydown',caps);p.addEventListener('keyup',caps);p.addEventListener('blur',function(){c.hidden=true});
77
- f.addEventListener('submit',function(){f.setAttribute('data-busy','')});
78
- addEventListener('pageshow',function(){f.removeAttribute('data-busy')});`;
79
- const EYE = '<svg class="show" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.42 12.713c-.136-.215-.204-.323-.242-.49a1.173 1.173 0 0 1 0-.446c.038-.167.106-.274.242-.49C3.546 9.505 6.895 5 12 5s8.455 4.505 9.58 6.287c.137.215.205.323.243.49.029.125.029.322 0 .446-.038.167-.106.274-.242.49C20.454 14.495 17.105 19 12 19S3.545 14.495 2.42 12.713Z"/><path d="M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></svg>' +
80
- '<svg class="hide" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.743 5.092C11.149 5.032 11.569 5 12 5c5.105 0 8.455 4.505 9.58 6.287.137.215.205.323.243.49.029.125.029.322 0 .446-.038.167-.107.275-.244.492-.3.474-.757 1.141-1.363 1.865M6.724 6.715c-2.162 1.467-3.63 3.504-4.303 4.57-.137.216-.205.324-.243.49a1.173 1.173 0 0 0 0 .446c.038.167.106.274.242.49C3.546 14.495 6.895 19 12 19c2.059 0 3.832-.732 5.289-1.723M3 3l18 18M9.879 9.879a3 3 0 1 0 4.243 4.243"/></svg>';
81
- function shell(siteName, body, script) {
56
+ function shell(siteName, page, body) {
82
57
  return `<!doctype html>
83
58
  <html lang="en">
84
59
  <head>
@@ -92,53 +67,43 @@ function shell(siteName, body, script) {
92
67
  <style>${CSS}</style>
93
68
  </head>
94
69
  <body>
95
- <main class="gate">
70
+ <main class="gate" data-gate="${page}">
96
71
  <h1>${escapeHtml(siteName)}</h1>
97
72
  ${body}
98
73
  </main>
99
- ${script ? `<script>${JS}</script>` : ''}
100
74
  </body>
101
75
  </html>
102
76
  `;
103
77
  }
104
- function passwordPage(siteName, failed) {
105
- const error = failed
106
- ? `<p id="err" class="note error" role="alert">That password didn’t match. Try again.</p>`
107
- : '';
108
- const invalid = failed ? ' aria-invalid="true" aria-describedby="err"' : '';
109
- return shell(siteName, `<p class="hint">Use the password from the message that shared this link.</p>
110
- <form method="post" novalidate>
111
- <label for="password">Password</label>
112
- <div class="field">
113
- <input id="password" name="password" type="password" autocomplete="current-password" autocapitalize="off" autocorrect="off" spellcheck="false" required autofocus maxlength="${MAX_PASSWORD_LENGTH}"${invalid}>
114
- <button id="toggle" class="toggle" type="button" aria-pressed="false" aria-label="Show password" aria-controls="password">${EYE}</button>
115
- </div>
116
- <p id="caps" class="note" aria-live="polite" hidden>Caps Lock is on.</p>
117
- ${error}
118
- <button class="go" type="submit">Open prototypes</button>
119
- </form>`, true);
120
- }
78
+ const signInPage = (siteName) => shell(siteName, 'sign-in', `<p>To sign in, open the link the studio sent you. Each link signs in one device, then stops working.</p>
79
+ <p>For another device, or if your link has stopped working, ask the studio for a new one.</p>`);
121
80
  // A GET shows who the link is for and a POST signs them in, so a mail
122
- // scanner that opens every link never uses the invite.
123
- function invitePage(siteName, person) {
124
- if (!person)
125
- return shell(siteName, `<p class="hint">This invite link has expired or was revoked. Ask whoever sent it for a new one.</p>`, false);
126
- return shell(siteName, `<p class="hint">You’re invited to review as <strong>${escapeHtml(person.name)}</strong>, ${escapeHtml(person.team)}.</p>
127
- <form method="post"><button class="go" type="submit" autofocus>Continue</button></form>`, false);
128
- }
129
- // `design-hub dev` has no gate; the Vite plugin serves this at /_gate/ so the page can be reviewed.
130
- export async function gatePreview(failed, siteName = DEFAULT_SITE_NAME) {
131
- return { html: passwordPage(siteName, failed), csp: (await csp()).withScript };
81
+ // scanner that opens every link never uses it up.
82
+ const linkPage = (siteName, person) => shell(siteName, 'link', `<p>This link signs in <strong>${escapeHtml(person.name)}</strong>, ${escapeHtml(person.team)}, on this device.</p>
83
+ <p>It works once. For another device, ask the studio for a new link.</p>
84
+ <form method="post"><button class="go" type="submit" autofocus>Continue</button></form>`);
85
+ // Someone who opens their link again on a device it already signed in gets
86
+ // here too, so the page offers the way in as well.
87
+ const usedPage = (siteName) => shell(siteName, 'used', `<p>This link has been used, has expired or was removed. Each link signs in one device, then stops working.</p>
88
+ <p>Ask the studio for a new one. If this device is already signed in, open the prototypes.</p>
89
+ <a class="go" href="/">Open the prototypes</a>`);
90
+ const SIGNED_OUT = 'Sign in with the link the studio sent you.';
91
+ const USED = 'This link has been used, has expired or was removed.';
92
+ const OPEN_IN_BROWSER = 'Open this link in a browser to sign in.';
93
+ const PREVIEWS = {
94
+ 'sign-in': signInPage,
95
+ link: (siteName) => linkPage(siteName, { name: 'Rae Chen', team: 'Acme' }),
96
+ used: usedPage,
97
+ };
98
+ // `design-hub dev` has no gate; the Vite plugin serves this at /_gate/ (?page=link or ?page=used) so the pages can be reviewed.
99
+ export async function gatePreview(page, siteName = DEFAULT_SITE_NAME) {
100
+ // hasOwn, so ?page=__proto__ or toString never reaches Object.prototype.
101
+ const render = page !== null && Object.hasOwn(PREVIEWS, page) ? PREVIEWS[page] : signInPage;
102
+ return { html: render(siteName), csp: await csp() };
132
103
  }
133
104
  let cspPromise;
134
105
  function csp() {
135
- cspPromise ??= Promise.all([sha256(CSS), sha256(JS)]).then(([css, js]) => {
136
- const base = `default-src 'none'; style-src 'sha256-${base64(css)}'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'`;
137
- return {
138
- withScript: `${base}; script-src 'sha256-${base64(js)}'`,
139
- noScript: `${base}; script-src 'none'`,
140
- };
141
- });
106
+ cspPromise ??= sha256(CSS).then((css) => `default-src 'none'; style-src 'sha256-${base64(css)}'; script-src 'none'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'`);
142
107
  return cspPromise;
143
108
  }
144
109
  const NO_STORE = 'no-store, max-age=0';
@@ -148,91 +113,152 @@ function wantsHtml(request) {
148
113
  return dest === 'document' || dest === 'iframe';
149
114
  return (request.headers.get('accept') ?? '').includes('text/html');
150
115
  }
151
- async function htmlPage(request, status, html, script, cookie) {
152
- const headers = new Headers({ 'cache-control': NO_STORE, 'x-robots-tag': 'noindex, nofollow' });
116
+ const isRead = (request) => request.method === 'GET' || request.method === 'HEAD';
117
+ /**
118
+ * Every answer the gate makes itself carries these: never cached, never
119
+ * indexed, no referrer. The link page alone sends a same-origin referrer, so
120
+ * its Continue POST carries a real Origin: with no-referrer a browser sends
121
+ * `Origin: null`, which sameOrigin trusts only beside Sec-Fetch-Site, and
122
+ * older Safari sends no Sec-Fetch-Site.
123
+ */
124
+ function gateHeaders(type, { cookie, allow, referrer = 'no-referrer', retryAfter }) {
125
+ const headers = new Headers({
126
+ 'cache-control': NO_STORE,
127
+ 'content-type': type,
128
+ 'x-robots-tag': 'noindex, nofollow',
129
+ 'referrer-policy': referrer,
130
+ });
153
131
  if (cookie)
154
132
  headers.append('set-cookie', cookie);
155
- if (!wantsHtml(request)) {
156
- headers.set('content-type', 'text/plain; charset=utf-8');
157
- return new Response(request.method === 'HEAD' ? null : 'Password required.', { status, headers });
158
- }
159
- const policy = await csp();
160
- headers.set('content-type', 'text/html; charset=utf-8');
161
- headers.set('content-security-policy', script ? policy.withScript : policy.noScript);
162
- headers.set('referrer-policy', 'no-referrer');
163
- return new Response(request.method === 'HEAD' ? null : html, { status, headers });
133
+ if (allow)
134
+ headers.set('allow', allow);
135
+ if (retryAfter)
136
+ headers.set('retry-after', String(retryAfter));
137
+ return headers;
164
138
  }
165
- const plain = (status, text, extra = {}) => new Response(text, {
139
+ const plain = (request, status, text, extra = {}) => new Response(request.method === 'HEAD' ? null : text, {
166
140
  status,
167
- headers: { 'cache-control': NO_STORE, 'content-type': 'text/plain; charset=utf-8', ...extra },
141
+ headers: gateHeaders('text/plain; charset=utf-8', extra),
168
142
  });
169
- const redirect = (location, cookie) => new Response(null, { status: 303, headers: { location, 'cache-control': NO_STORE, 'set-cookie': cookie } });
170
- async function readPassword(request) {
171
- if (!(request.headers.get('content-type') ?? '').startsWith('application/x-www-form-urlencoded'))
172
- return null;
143
+ /** A gate page for a browser, or `text` for anything else (a fetch, an asset, a preview bot). */
144
+ async function page(request, status, html, text, extra = {}) {
145
+ if (!wantsHtml(request))
146
+ return plain(request, status, text, extra);
147
+ const headers = gateHeaders('text/html; charset=utf-8', extra);
148
+ headers.set('content-security-policy', await csp());
149
+ return new Response(request.method === 'HEAD' ? null : html, { status, headers });
150
+ }
151
+ const unavailable = (request, error) => plain(request, 503, error);
152
+ /** The store did not answer: a 503 that passes, so it says when to try again. */
153
+ const storeDown = (request) => plain(request, 503, STORE_DOWN, { retryAfter: 30 });
154
+ const STORE_DOWN = 'The review store did not answer. Try again in a minute.';
155
+ const NO_STORE_YET = 'Review is not set up on this site: pnpm bootstrap --vercel <project> --review.';
156
+ /**
157
+ * A store call that can fail without signing anyone out: `undefined` when the
158
+ * store did not answer, so the caller answers 503 and leaves the cookie alone.
159
+ */
160
+ async function ask(run) {
173
161
  try {
174
- const value = (await request.formData()).get('password');
175
- return typeof value === 'string' && value.length <= MAX_PASSWORD_LENGTH ? value : null;
162
+ return await run();
176
163
  }
177
- catch {
178
- return null;
164
+ catch (error) {
165
+ console.error('[gate]', error);
166
+ return undefined;
179
167
  }
180
168
  }
181
- async function invite(siteName, request, token) {
182
- const setup = deployedReview(process.env);
169
+ async function showLink(ctx, token) {
170
+ const { siteName, request } = ctx;
171
+ const setup = deployedReview(process.env, null, () => ctx.at);
183
172
  if ('error' in setup)
184
- return plain(503, setup.error);
185
- if (request.method === 'POST' && !sameOrigin(request))
186
- return plain(403, 'Forbidden');
187
- const person = await setup.review.acceptInvite(token);
188
- if (request.method !== 'POST' || !person)
189
- return htmlPage(request, person ? 200 : 404, invitePage(siteName, person), false);
190
- const cookie = sessionCookie(PERSON_COOKIE, await issuePersonToken(setup.gate, { id: person.id, epoch: person.epoch }));
191
- return redirect('/', cookie);
173
+ return unavailable(request, setup.error);
174
+ const person = await ask(() => setup.review.peekLink(token));
175
+ if (person === undefined)
176
+ return storeDown(request);
177
+ return person
178
+ ? page(request, 200, linkPage(siteName, person), OPEN_IN_BROWSER, { referrer: 'same-origin' })
179
+ : page(request, 404, usedPage(siteName), USED);
192
180
  }
193
- const pass = () => next({ headers: { 'cache-control': 'private, no-store' } });
194
- // The signature alone admits assets; a page load also asks the store, so a
195
- // revoke lands on the person's next navigation without a store read per asset.
196
- async function personSession(siteName, request, claim) {
197
- if (!wantsHtml(request))
198
- return pass();
199
- const setup = deployedReview(process.env);
200
- const current = 'error' in setup ? null : await setup.review.sessionPerson(claim.id, claim.epoch).catch(() => null);
201
- if (current)
202
- return pass();
203
- return htmlPage(request, 401, passwordPage(siteName, false), true, clearedCookie(PERSON_COOKIE));
181
+ /** The cookie for someone the store just said yes to, lasting to their access end. */
182
+ async function sessionFor(gate, person, at) {
183
+ const token = await issuePersonToken(gate, { id: person.id, epoch: person.epoch }, person.accessEndsAt, at);
184
+ return sessionCookie(PERSON_COOKIE, token, sessionSeconds(person.accessEndsAt, at));
204
185
  }
205
- async function passwordPost(siteName, request, gate, url) {
186
+ async function signInWithLink(ctx, token) {
187
+ const { siteName, request, at } = ctx;
206
188
  if (!sameOrigin(request))
207
- return plain(403, 'Forbidden');
208
- const submitted = await readPassword(request);
209
- if (submitted === null || !(await passwordMatches(gate, submitted))) {
210
- await new Promise((resolve) => setTimeout(resolve, WRONG_PASSWORD_DELAY_MS));
211
- return htmlPage(request, 401, passwordPage(siteName, true), true);
212
- }
213
- return redirect(url.pathname + url.search, sessionCookie(GATE_COOKIE, await issueGateToken(gate)));
189
+ return plain(request, 403, 'Forbidden');
190
+ const setup = deployedReview(process.env, null, () => ctx.at);
191
+ if ('error' in setup)
192
+ return unavailable(request, setup.error);
193
+ const person = await ask(() => setup.review.useLink(token));
194
+ if (person === undefined)
195
+ return storeDown(request);
196
+ if (!person)
197
+ return page(request, 404, usedPage(siteName), USED);
198
+ const headers = gateHeaders('text/plain; charset=utf-8', {
199
+ cookie: await sessionFor(setup.gate, person, at),
200
+ });
201
+ headers.set('location', '/');
202
+ return new Response(null, { status: 303, headers });
203
+ }
204
+ async function link(ctx, token) {
205
+ if (ctx.request.method === 'POST')
206
+ return signInWithLink(ctx, token);
207
+ if (isRead(ctx.request))
208
+ return showLink(ctx, token);
209
+ return plain(ctx.request, 405, 'Method not allowed', { allow: 'GET, HEAD, POST' });
210
+ }
211
+ /**
212
+ * No session. A page gets the sign-in page, and anything else (an asset, a
213
+ * fetch, a POST to any path but a link) a plain 401: there is nothing to
214
+ * sign in with here. A cookie that was sent but does not hold is cleared.
215
+ */
216
+ function signedOut({ siteName, request }, staleCookie) {
217
+ const extra = staleCookie ? { cookie: clearedCookie(PERSON_COOKIE) } : {};
218
+ if (!isRead(request))
219
+ return plain(request, 401, SIGNED_OUT, extra);
220
+ return page(request, 401, signInPage(siteName), SIGNED_OUT, extra);
221
+ }
222
+ const pass = (cookie) => next({ headers: { 'cache-control': 'private, no-store', ...(cookie ? { 'set-cookie': cookie } : {}) } });
223
+ /**
224
+ * A signed session. While the store's last yes is fresh the signature is
225
+ * enough. Once it is stale the store is asked, whatever the request says it
226
+ * is (its headers are the client's to choose): yes passes with a fresh cookie
227
+ * whose expiry follows the person's current access end; no signs out and
228
+ * clears the cookie; no answer is 503 and the cookie stays.
229
+ */
230
+ async function personSession(ctx, gate, claim) {
231
+ if (isFresh(claim, ctx.at))
232
+ return pass();
233
+ const setup = deployedReview(process.env, null, () => ctx.at);
234
+ if ('error' in setup)
235
+ return unavailable(ctx.request, setup.error);
236
+ const current = await ask(() => setup.review.sessionPerson(claim.id, claim.epoch));
237
+ if (current === undefined)
238
+ return storeDown(ctx.request);
239
+ return current ? pass(await sessionFor(gate, current, ctx.at)) : signedOut(ctx, true);
214
240
  }
215
241
  /** The middleware a project's proxy.ts default-exports. */
216
- export function createProxy({ siteName = DEFAULT_SITE_NAME } = {}) {
242
+ export function createProxy({ siteName = DEFAULT_SITE_NAME, now = () => new Date() } = {}) {
217
243
  return async function proxy(request) {
218
244
  const gate = readGate(process.env);
219
245
  if (!gate)
220
- return plain(503, 'The prototype gate is not configured.');
246
+ return unavailable(request, 'The prototype gate is not configured.');
247
+ const ctx = { siteName, request, at: now() };
221
248
  const url = new URL(request.url);
222
- const invited = url.pathname.match(INVITE_PATH);
223
- if (invited && ['GET', 'HEAD', 'POST'].includes(request.method))
224
- return invite(siteName, request, invited[1]);
225
- if (GATE_ASSETS.has(url.pathname) && (request.method === 'GET' || request.method === 'HEAD'))
249
+ const linked = url.pathname.match(LINK_PATH);
250
+ if (linked)
251
+ return link(ctx, linked[1]);
252
+ if (GATE_ASSETS.has(url.pathname) && isRead(request))
226
253
  return next();
227
- if (await gateTokenIsValid(gate, readCookie(request, GATE_COOKIE)))
228
- return pass();
229
- const claim = await readPersonToken(gate, readCookie(request, PERSON_COOKIE));
254
+ const cookie = readCookie(request, PERSON_COOKIE);
255
+ const claim = await readPersonToken(gate, cookie, ctx.at);
230
256
  if (claim)
231
- return personSession(siteName, request, claim);
232
- if (request.method === 'GET' || request.method === 'HEAD')
233
- return htmlPage(request, 401, passwordPage(siteName, false), true);
234
- if (request.method === 'POST')
235
- return passwordPost(siteName, request, gate, url);
236
- return plain(405, 'Method not allowed', { allow: 'GET, HEAD, POST' });
257
+ return personSession(ctx, gate, claim);
258
+ // Tokens are signed to the store's URL, so without one none verifies. Clearing cookies then
259
+ // would turn a missing env var into everyone locked out, since links work once: answer 503 instead.
260
+ if (cookie !== undefined && gate.site === '')
261
+ return unavailable(request, NO_STORE_YET);
262
+ return signedOut(ctx, cookie !== undefined);
237
263
  };
238
264
  }
@@ -19,10 +19,10 @@ import { lapse } from './lapse.js';
19
19
  import { markdownDocs } from './markdown.js';
20
20
  import { registry } from './registry.js';
21
21
  const require = createRequire(import.meta.url);
22
- // The password page loads before sign-in, so it cannot reach the hashed
23
- // bundle. Its font goes out at the one fixed path the gate lets through.
24
- // `design-hub dev` has no gate, so there /_gate/ previews the page (?failed
25
- // shows the wrong-password state).
22
+ // The gate pages load before sign-in, so they cannot reach the hashed
23
+ // bundle. Their font goes out at the one fixed path the gate lets through.
24
+ // `design-hub dev` has no gate, so there /_gate/ previews the sign-in page,
25
+ // ?page=link a link's page and ?page=used a used or expired link's.
26
26
  const gateFontFile = () => join(dirname(require.resolve('@fontsource-variable/geist')), 'files', 'geist-latin-wght-normal.woff2');
27
27
  function gateFont() {
28
28
  return {
@@ -40,7 +40,7 @@ function gateFont() {
40
40
  }
41
41
  if (url.pathname !== '/_gate/')
42
42
  return nextMiddleware();
43
- const page = await gatePreview(url.searchParams.has('failed'));
43
+ const page = await gatePreview(url.searchParams.get('page'));
44
44
  res.setHeader('content-type', 'text/html; charset=utf-8');
45
45
  res.setHeader('content-security-policy', page.csp);
46
46
  res.end(page.html);
package/kit/ui/Menu.tsx CHANGED
@@ -327,6 +327,8 @@ function MenuRow({
327
327
  disabled={item.disabled}
328
328
  data-label={item.label}
329
329
  onClick={() => onPick(item)}
330
+ // The pointer takes the highlight from the keyboard, so one row is lit, never two.
331
+ onPointerMove={(e) => e.currentTarget.focus({ preventScroll: true })}
330
332
  >
331
333
  {item.icon ? (
332
334
  <span className="menu-glyph">
@@ -347,7 +349,11 @@ function MenuRow({
347
349
  );
348
350
  }
349
351
 
350
- export type SelectOption = { value: string; label: string };
352
+ /** `desc` is a second, quieter line in the list; the closed control shows the label alone. */
353
+ const selectValueClass = (set: boolean, picked: boolean) =>
354
+ ['select-value', !set && 'is-placeholder', picked && 'is-picked'].filter(Boolean).join(' ');
355
+
356
+ export type SelectOption = { value: string; label: string; desc?: string };
351
357
 
352
358
  export function Select({
353
359
  value,
@@ -371,17 +377,21 @@ export function Select({
371
377
  'aria-label'?: string;
372
378
  }) {
373
379
  const valueId = useId();
380
+ // Set on the first pick, so the value settles in when it changes and not when the control mounts.
381
+ const picked = useRef(false);
374
382
  const current = options.find((o) => o.value === value);
375
383
  const menu = useMenu({
376
384
  role: 'listbox',
377
385
  align: 'start',
378
- items: options.map((o) => ({ label: o.label, value: o.value })),
386
+ items: options.map((o) => ({ label: o.label, value: o.value, desc: o.desc })),
379
387
  selected: value ?? undefined,
380
388
  label: ariaLabel,
381
389
  className: menuClassName,
382
390
  width: (trigger) => Math.max(trigger.offsetWidth, width || 0),
383
391
  onSelect: (v) => {
384
- if (v != null && v !== value) onChange(v);
392
+ if (v == null || v === value) return;
393
+ picked.current = true;
394
+ onChange(v);
385
395
  },
386
396
  });
387
397
  return (
@@ -399,7 +409,7 @@ export function Select({
399
409
  if (!menu.isOpen) menu.open();
400
410
  }}
401
411
  >
402
- <span id={valueId} className={current ? 'select-value' : 'select-value is-placeholder'}>
412
+ <span key={value} id={valueId} className={selectValueClass(!!current, picked.current)}>
403
413
  {current ? current.label : placeholder}
404
414
  </span>
405
415
  <Icon name="chevron-down" size={20} className="select-chevron" />
package/kit/ui/ui.css CHANGED
@@ -60,9 +60,13 @@ body.has-overlay { overflow: hidden; }
60
60
  .search { position: relative; }
61
61
  .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--fg-quaternary); }
62
62
  .search .input { padding-left: 32px; }
63
- .select { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; text-align: left; }
63
+ /* The value starts where an input's text does. The right padding puts the chevron's ink over the check in the list below. */
64
+ .select { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; padding-right: 10px; cursor: pointer; text-align: left; }
64
65
  .select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
65
66
  .select-value.is-placeholder { color: var(--text-placeholder); }
67
+ /* A picked value settles in from just below: the control answers the choice the menu took away. */
68
+ .select-value.is-picked { animation: select-pick var(--dur-menu) var(--ease-out); }
69
+ @keyframes select-pick { from { opacity: 0; transform: translateY(3px); } }
66
70
  .select { transition: border-color var(--dur-hover) var(--ease-hover), background-color var(--dur-hover) var(--ease-hover); }
67
71
  .select-chevron { color: var(--fg-quaternary); transition: transform var(--dur-menu) var(--ease-out); }
68
72
  @media (hover: hover) and (pointer: fine) { .select:hover:not([aria-expanded="true"]) { background: var(--button-secondary-bg_hover); } }
@@ -155,8 +159,12 @@ body.has-overlay { overflow: hidden; }
155
159
  .menu-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); border: 0; background: transparent; text-align: left; cursor: pointer; width: 100%; color: var(--text-primary); position: relative; --press-dur: var(--dur-press-out); transition: transform var(--press-dur) var(--ease-out), background-color var(--dur-hover) var(--ease-hover); }
156
160
  .menu-item:focus-visible, .menu-item.has-open, .menu-item.is-pressed { background: var(--bg-primary_hover); box-shadow: none; }
157
161
  @media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--bg-primary_hover); box-shadow: none; } .menu-item:hover .menu-glyph { color: var(--fg-secondary); } }
162
+ /* The highlight lands at once and fades behind the pointer: a row answers before the hand settles. */
163
+ .menu-item:is(:hover, :focus-visible) { transition-duration: var(--press-dur), 0ms; }
158
164
  .menu-item.is-pressed { --press-dur: var(--dur-press-in); transform: scale(0.995); }
159
165
  .menu-item[disabled] { color: var(--text-disabled); cursor: not-allowed; }
166
+ /* A select's list sits under its control: 1px less padding puts each label under the value. */
167
+ .menu[role="listbox"] .menu-item { padding-inline: 9px; }
160
168
  /* A menu row is a finger's target where the pointer is one. */
161
169
  @media (pointer: coarse) { .menu-item { min-height: 44px; } }
162
170
  .menu-glyph { color: var(--fg-quaternary); display: grid; place-items: center; }
@@ -164,9 +172,13 @@ body.has-overlay { overflow: hidden; }
164
172
  .menu-item.is-danger { color: var(--text-error-primary); }
165
173
  .menu-item.is-danger .menu-glyph { color: var(--fg-error-primary); }
166
174
  .menu-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
175
+ /* One weight in every state, so choosing a row never reflows it: the check says which is chosen. */
167
176
  .menu-label { font-weight: 500; }
168
- .menu-item.is-selected .menu-label { font-weight: 600; }
169
- .menu-desc { color: var(--text-tertiary); font-size: 12px; line-height: 18px; }
177
+ .menu-desc { color: var(--text-tertiary); font-size: 12px; line-height: 16px; text-wrap: pretty; }
178
+ /* A row with a second line: its glyph and check sit on the label's line, not between the two. */
179
+ .menu-item:has(.menu-desc) { align-items: flex-start; }
180
+ .menu-item:has(.menu-desc) .menu-text { gap: 2px; }
181
+ .menu-item:has(.menu-desc) :is(.menu-glyph, .menu-check, .menu-chevron) { height: 1lh; }
170
182
  .menu-keys { display: flex; gap: 4px; margin-left: auto; flex: none; }
171
183
  .kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border: 1px solid var(--border-secondary); border-radius: var(--radius-xs); font: 500 12px/18px var(--font); color: var(--text-tertiary); }
172
184
  .kbd:has(.icon) { padding: 0; color: var(--fg-quaternary); }
@@ -230,6 +242,7 @@ body.has-overlay { overflow: hidden; }
230
242
  /* ---------- motion gates ---------- */
231
243
  :root[data-motion="reduce"] :is(.btn, .btn .icon, .select, .select-chevron, .menu-item) { transition-duration: 0ms; }
232
244
  :root[data-motion="reduce"] .menu-item.is-pressed { transform: none; }
245
+ :root[data-motion="reduce"] .select-value.is-picked { animation: none; }
233
246
  :root[data-motion="reduce"] :is(.menu, .menu[data-side], .menu.is-open, .dialog, .overlay.is-open .dialog) { transform: none; transition: opacity 160ms var(--ease-hover); }
234
247
  :root[data-motion="reduce"] :is(.sheet, .overlay.is-open .sheet) { transform: none; transition: opacity 160ms var(--ease-hover); }
235
248
  :root[data-motion="reduce"] .overlay-sheet:not(.is-open) .sheet { opacity: 0; }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.6.1",
4
- "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
3
+ "version": "0.7.0",
4
+ "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the sign-in gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,7 +16,8 @@ type Props = {
16
16
  onScope: (scope: Scope) => void;
17
17
  resolved: boolean;
18
18
  resolvedCount: number;
19
- editor: boolean;
19
+ /** Studio only: the People entry in ⋯. */
20
+ canManagePeople: boolean;
20
21
  error: string | null;
21
22
  onStep: (by: number) => void;
22
23
  onResolved: () => void;
@@ -26,7 +27,7 @@ type Props = {
26
27
  onDismissError: () => void;
27
28
  };
28
29
 
29
- function moreItems(resolved: boolean, resolvedCount: number, editor: boolean): MenuEntry[] {
30
+ function moreItems(resolved: boolean, resolvedCount: number, canManagePeople: boolean): MenuEntry[] {
30
31
  return [
31
32
  {
32
33
  label: resolved ? 'Hide resolved' : 'Show resolved',
@@ -35,7 +36,7 @@ function moreItems(resolved: boolean, resolvedCount: number, editor: boolean): M
35
36
  icon: 'check-circle',
36
37
  disabled: !resolvedCount && !resolved,
37
38
  },
38
- ...(editor
39
+ ...(canManagePeople
39
40
  ? [{ label: 'People', desc: 'Who can comment', value: 'people', icon: 'users-01' as const }]
40
41
  : []),
41
42
  { label: 'Hide comments', desc: 'Tuck the button into the edge', value: 'hide', icon: 'chevron-right' },
@@ -119,7 +120,7 @@ export function Bar(p: Props) {
119
120
  label: 'Comment options',
120
121
  width: 264,
121
122
  align: 'end',
122
- items: moreItems(p.resolved, p.resolvedCount, p.editor),
123
+ items: moreItems(p.resolved, p.resolvedCount, p.canManagePeople),
123
124
  onSelect: (v) => actions[v ?? '']?.(),
124
125
  });
125
126
  return (