@milesroxas/design-hub 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +4 -2
  2. package/core/prototype.test.ts +52 -0
  3. package/core/prototype.ts +59 -0
  4. package/core/review/model.ts +32 -3
  5. package/core/review/service.test.ts +240 -0
  6. package/core/review/service.ts +281 -50
  7. package/core/review/store.ts +10 -4
  8. package/dist/core/prototype.d.ts +50 -0
  9. package/dist/core/prototype.js +38 -0
  10. package/dist/core/review/model.d.ts +25 -1
  11. package/dist/core/review/model.js +18 -2
  12. package/dist/core/review/service.d.ts +98 -16
  13. package/dist/core/review/service.js +254 -45
  14. package/dist/core/review/store.d.ts +10 -4
  15. package/dist/scripts/client.d.ts +3 -3
  16. package/dist/scripts/client.js +52 -66
  17. package/dist/scripts/lib/dns.d.ts +32 -0
  18. package/dist/scripts/lib/dns.js +69 -1
  19. package/dist/scripts/lib/fake-host.d.ts +34 -9
  20. package/dist/scripts/lib/fake-host.js +7 -4
  21. package/dist/scripts/lib/review.d.ts +5 -2
  22. package/dist/scripts/lib/review.js +8 -2
  23. package/dist/scripts/lib/studios.d.ts +3 -1
  24. package/dist/scripts/lib/studios.js +2 -0
  25. package/dist/scripts/people.d.ts +8 -5
  26. package/dist/scripts/people.js +152 -41
  27. package/dist/scripts/share.js +1 -1
  28. package/dist/scripts/studio.d.ts +3 -3
  29. package/dist/scripts/studio.js +100 -10
  30. package/dist/server/api.d.ts +6 -8
  31. package/dist/server/api.js +129 -42
  32. package/dist/server/hosts.d.ts +3 -3
  33. package/dist/server/hosts.js +10 -10
  34. package/dist/server/session.d.ts +7 -0
  35. package/dist/server/session.js +8 -1
  36. package/dist/vercel/proxy.d.ts +7 -3
  37. package/dist/vercel/proxy.js +215 -49
  38. package/dist/vite/plugin.d.ts +6 -2
  39. package/dist/vite/plugin.js +21 -3
  40. package/package.json +1 -1
  41. package/shell/Index.tsx +29 -0
  42. package/shell/review/People.tsx +80 -61
  43. package/shell/review/Review.tsx +49 -1
  44. package/shell/review/ThreadCard.tsx +13 -1
  45. package/shell/review/client.ts +56 -22
  46. package/shell/review/review.css +1 -0
  47. package/shell/review/unsent.test.ts +63 -0
  48. package/shell/review/unsent.ts +64 -0
  49. package/shell/review/view.ts +22 -6
  50. package/shell/studio/ClientHub.tsx +9 -36
  51. package/shell/studio/StudioHub.tsx +293 -0
  52. package/shell/studio/hub.css +80 -5
  53. package/shell/studio/page.tsx +57 -0
  54. package/shell/studio/studio.html +14 -0
  55. package/shell/studio/studio.tsx +19 -0
  56. package/skills/miles-deploy/SKILL.md +16 -6
  57. package/skills/miles-design-hub/SKILL.md +3 -3
  58. package/skills/miles-review/SKILL.md +1 -1
  59. package/templates/studio/README.md +32 -13
  60. package/templates/studio/package.json +1 -1
@@ -2,46 +2,60 @@
2
2
  /// <reference types="node" />
3
3
  // The people who comment on a project's prototypes in its studio: its
4
4
  // client's people, each signing in with a one-time link on the client's own
5
- // host. A link signs in one device, then stops working, so a second device
6
- // needs a new link. Studio also adds people from the People tab. Without a
7
- // link to a studio, and with --local, they are this machine's dev store's,
8
- // whose links open nothing anywhere.
9
- import { ACCESS, PERSON_KINDS } from '../core/review/model.js';
5
+ // host, and the studio's own people. A link signs in one device, then stops
6
+ // working, so a second device needs a new link. A Studio person's link is on
7
+ // the studio's own host (studio.<apex>) once it answers, where they see every
8
+ // client; before then, on the linked project's client's host. In the studio
9
+ // folder, or with --studio, people are the studio's own: that is how a Studio
10
+ // person, the owner too, gets a new link without a session. Studio also adds
11
+ // people from the People tab and the studio hub. Without a link to a studio,
12
+ // and with --local, they are this machine's dev store's, whose links open
13
+ // nothing anywhere.
14
+ import { ACCESS, PERSON_KINDS, STUDIO_SITE } from '../core/review/model.js';
15
+ import { localStudio } from '../server/local.js';
10
16
  import { CliError } from './lib/cli.js';
11
- import { realProjectDeps } from './lib/linked.js';
12
- import { cliActor, cliReview } from './lib/review.js';
17
+ import { readLink, realProjectDeps } from './lib/linked.js';
18
+ import { cliReview } from './lib/review.js';
19
+ import { openReview } from './lib/studio-deps.js';
20
+ import { findStudio, isStudioFolder, studioHost } from './lib/studios.js';
13
21
  export const spec = {
14
22
  name: 'people',
15
23
  summary: 'List or add the people who comment on the deployed prototypes, give them sign-in links, sign them out, revoke them, and set how long they keep access.',
16
24
  positionals: [
17
25
  {
18
26
  name: 'action',
19
- description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (the client’s own, else the studio’s), or sets the client’s with --access.',
27
+ description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (in a project the client’s own, else the studio’s; in the studio folder or with --studio the studio’s), or sets it with --access.',
20
28
  },
21
29
  { name: 'id', description: 'The person, for link, sign-out, revoke and access' },
22
30
  ],
23
31
  flags: {
24
32
  name: { type: 'string', description: 'For add: their name as it shows on comments.' },
25
- team: { type: 'string', description: "For add: the studio, or the client's company." },
33
+ team: {
34
+ type: 'string',
35
+ description: "For add: shown beside their name. Absent, the studio's name for studio and the client's name for client.",
36
+ },
26
37
  kind: {
27
38
  type: 'string',
28
- default: 'client',
29
39
  choices: PERSON_KINDS,
30
- description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and manages people.',
40
+ description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts, manages people and sees every client at studio.<apex>. Absent: client in a project, studio in the studio folder or with --studio, which take studio only.',
31
41
  },
32
42
  access: {
33
43
  type: 'string',
34
44
  choices: ACCESS,
35
45
  description: 'How long they keep access: 3m, 6m or open. For add, absent means the client’s default for a client (people access reads it) and open for studio.',
36
46
  },
47
+ studio: {
48
+ type: 'string',
49
+ description: 'The studio whose own people these are, by slug, from anywhere on this machine; in the studio folder it is that studio. Their links are on studio.<apex>. Client people are a project’s: run people in the project linked to their client.',
50
+ },
37
51
  local: {
38
52
  type: 'boolean',
39
53
  description: 'Use this machine’s dev store, even in a project linked to a studio.',
40
54
  },
41
55
  },
42
- output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; local otherwise',
56
+ output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; store is studio with studio: { studio, host } for the studio’s own people (the studio folder or --studio); local otherwise. A Studio person’s link is on studio.<apex> once it answers.',
43
57
  };
44
- /** A link on the client's own host; a local one is a path the dev server never asks for. */
58
+ /** A link on the host it signs in on; a local one is a path the dev server never asks for. */
45
59
  const linkFor = (token, host) => {
46
60
  const path = `/invite/${token}`;
47
61
  if (!host)
@@ -57,55 +71,152 @@ function needId(action, id) {
57
71
  throw new CliError(`Name the person: pnpm people ${action} <id>.`, { fix: 'pnpm people lists ids.' });
58
72
  return id;
59
73
  }
60
- const withLink = (r, host) => ({
61
- person: strip(r.person),
62
- ...linkFor(r.token, host),
63
- });
74
+ async function withLink(r, c) {
75
+ return { person: strip(r.person), ...linkFor(r.token, await c.hostFor(r.person)) };
76
+ }
64
77
  /** One person's access with an id, else the default for a new Client: read it, or set it with --access. */
65
- async function access({ review, scope, actor, flags, id }) {
78
+ async function access({ review, at, actor, flags, id }) {
66
79
  if (id) {
67
80
  if (!flags.access)
68
81
  throw new CliError('Say how long: pnpm people access <id> --access 3m|6m|open.');
69
- return { person: strip(await review.setAccess(scope, actor, id, flags.access)) };
82
+ return { person: strip(await review.setAccess(at, actor, id, flags.access)) };
70
83
  }
84
+ if (at === STUDIO_SITE)
85
+ return {
86
+ access: flags.access
87
+ ? await review.setStudioAccess(actor, flags.access)
88
+ : await review.studioAccess(actor),
89
+ };
71
90
  return {
72
91
  access: flags.access
73
- ? await review.setDefaultAccess(scope, actor, flags.access)
74
- : await review.defaultAccess(scope, actor),
92
+ ? await review.setDefaultAccess(at, actor, flags.access)
93
+ : await review.defaultAccess(at, actor),
75
94
  };
76
95
  }
77
- /** What adding a Studio person in a linked project means, in plain words. */
78
- const studioWide = ({ studio, client, host }) => `A Studio person sees every client of studio ${studio}, not only ${client}: every project, comment and person. This link signs them in on ${host}. For someone who should see ${client} alone, add them with --kind client.`;
96
+ /** What adding a Studio person from a linked project means, in plain words, with --kind studio or --studio alike. */
97
+ const studioWide = ({ studio, client }, link) => `A Studio person sees every client of studio ${studio}, not only ${client}: every project, comment and person. This link signs them in on ${new URL(link).host}. For someone who should see ${client} alone, add them in this project with --kind client and no --studio.`;
98
+ /** The actions that print a link: a run that cannot print one is refused before any of them writes. */
99
+ const LINKING = new Set(['add', 'link', 'sign-out']);
79
100
  const ACTIONS = {
80
- list: async ({ review, scope, actor }) => ({ people: (await review.listPeople(scope, actor)).map(strip) }),
81
- add: async ({ review, scope, actor, flags, host }) => withLink(await review.addPerson(scope, actor, {
82
- name: flags.name,
83
- team: flags.team,
84
- kind: flags.kind,
85
- access: flags.access,
86
- }), host),
87
- link: async ({ review, scope, actor, id, host }) => withLink(await review.newLink(scope, actor, needId('link', id)), host),
88
- 'sign-out': async ({ review, scope, actor, id, host }) => withLink(await review.signOutEverywhere(scope, actor, needId('sign-out', id)), host),
89
- revoke: async ({ review, scope, actor, id }) => ({
90
- person: strip(await review.revoke(scope, actor, needId('revoke', id))),
101
+ list: async ({ review, at, actor }) => ({ people: (await review.listPeople(at, actor)).map(strip) }),
102
+ add: async (c) => withLink(await c.review.addPerson(c.at, c.actor, {
103
+ name: c.flags.name,
104
+ team: c.flags.team,
105
+ kind: c.flags.kind ?? (c.at === STUDIO_SITE ? 'studio' : 'client'),
106
+ access: c.flags.access,
107
+ }), c),
108
+ link: async (c) => withLink(await c.review.newLink(c.at, c.actor, needId('link', c.id)), c),
109
+ 'sign-out': async (c) => withLink(await c.review.signOutEverywhere(c.at, c.actor, needId('sign-out', c.id)), c),
110
+ revoke: async ({ review, at, actor, id }) => ({
111
+ person: strip(await review.revoke(at, actor, needId('revoke', id))),
91
112
  }),
92
113
  access,
93
114
  };
115
+ /**
116
+ * The studio's own host while it answers (its proof passed in `studio
117
+ * create` or `studio deploy`), else null: no link may be printed for a host
118
+ * that is not yet the studio site.
119
+ */
120
+ async function answeringStudioHost(review, actor, apex) {
121
+ return (await review.studioHostProven(actor)) ? studioHost(apex) : null;
122
+ }
123
+ /**
124
+ * The studio's own people (`--studio`, or the studio folder): its store, once
125
+ * its mark says it is its own, at the studio's own host. Client people are a
126
+ * project's, so --kind client is refused here before anything is opened.
127
+ */
128
+ async function studioPeople(flags, deps) {
129
+ if (flags.local)
130
+ throw new CliError('--studio and --local name two different stores.', {
131
+ fix: 'Drop one: --studio for the studio’s own people, --local for this machine’s dev store.',
132
+ });
133
+ if (flags.kind === 'client')
134
+ throw new CliError('Client people belong to a client: none is named here.', {
135
+ code: 'studio_people',
136
+ fix: 'Run people add in a project linked to the client (design-hub project link), or give a new client its first person with design-hub client add.',
137
+ });
138
+ // Without --studio, the studio folder this runs in (the project root a command is given).
139
+ const studio = findStudio(deps.home, flags.studio, deps.root);
140
+ const review = await openReview(deps, studio);
141
+ const actor = localStudio('cli', studio.config.name);
142
+ const { slug, apex } = studio.config;
143
+ return {
144
+ review,
145
+ actor,
146
+ at: STUDIO_SITE,
147
+ store: 'studio',
148
+ studio: { studio: slug, host: studioHost(apex) },
149
+ // Checked before the action runs (canLink), so a person, a link or a sign out is never made for no link.
150
+ hostFor: async () => studioHost(apex),
151
+ async canLink() {
152
+ if (await answeringStudioHost(review, actor, apex))
153
+ return;
154
+ throw new CliError(`${studioHost(apex)} does not answer yet; nothing was changed.`, {
155
+ code: 'studio_host_waiting',
156
+ fix: `Run design-hub studio deploy --studio ${slug}. It prints the owner's link once the host answers; then this works.`,
157
+ });
158
+ },
159
+ };
160
+ }
161
+ /**
162
+ * A project's people: a linked project's client in its studio, else this
163
+ * machine's dev store. A Studio person's link is on the studio's own host
164
+ * once it answers, a Client's on their client's host.
165
+ */
166
+ async function projectPeople(flags, deps) {
167
+ const found = await cliReview(flags.local, deps);
168
+ const { review, store, scope, actor } = found;
169
+ const where = found.studio;
170
+ if (!where)
171
+ return { review, store, at: scope, actor, hostFor: async () => undefined };
172
+ return {
173
+ review,
174
+ store,
175
+ at: scope,
176
+ actor,
177
+ studio: where,
178
+ async hostFor(person) {
179
+ if (person.client !== null)
180
+ return where.host;
181
+ const { apex } = findStudio(deps.home, where.studio, deps.cwd).config;
182
+ return (await answeringStudioHost(review, actor, apex)) ?? where.host;
183
+ },
184
+ };
185
+ }
94
186
  export async function run({ positionals: [action = 'list', id], flags }, deps) {
95
187
  const act = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
96
188
  if (!act)
97
189
  throw new CliError(`Unknown action ${action}.`, { fix: 'list, add, link, sign-out, revoke or access' });
98
- const found = await cliReview(flags.local, deps);
99
- const { review, store, scope } = found;
100
- // A linked project's links sign in on its client's own host, and nowhere else.
101
- const done = await act({ review, scope, actor: cliActor(), flags, id, host: found.studio?.host });
190
+ // The studio's own people: named by --studio, or the studio folder this runs in.
191
+ const own = flags.studio !== undefined || (!flags.local && !readLink(deps.root) && isStudioFolder(deps.root));
192
+ const found = own ? await studioPeople(flags, deps) : await projectPeople(flags, deps);
193
+ const { store, studio, canLink, ...context } = found;
194
+ if (canLink && LINKING.has(action))
195
+ await canLink();
196
+ const done = await act({ ...context, flags, id });
197
+ const project = own ? linkedHere(deps.root, studio?.studio) : studio && 'client' in studio ? studio : null;
198
+ const studioAdded = project && action === 'add' && done.person.client === null;
102
199
  return {
103
200
  store,
104
- ...(found.studio ? { studio: found.studio } : {}),
201
+ ...(studio ? { studio } : {}),
105
202
  ...done,
106
- ...(found.studio && action === 'add' && flags.kind === 'studio'
107
- ? { notice: studioWide(found.studio) }
203
+ ...(studioAdded
204
+ ? { notice: studioWide(project, String(done.link)) }
108
205
  : {}),
109
206
  };
110
207
  }
208
+ /**
209
+ * The client of the project this runs in, when it is linked to `studio`: a
210
+ * Studio person added there with --studio sees more than it. A link that
211
+ * cannot be read, or to another studio, is none here.
212
+ */
213
+ function linkedHere(root, studio) {
214
+ try {
215
+ const link = readLink(root);
216
+ return link && link.studio === studio ? link : null;
217
+ }
218
+ catch {
219
+ return null;
220
+ }
221
+ }
111
222
  export const main = (args) => run(args, realProjectDeps());
@@ -101,7 +101,7 @@ export async function run({ flags }, deps) {
101
101
  ...(guide ? { guide: `${address}${guide}` } : {}),
102
102
  })),
103
103
  ...(await prune(store, scope)),
104
- next: `Send ${address} with each person’s own sign-in link: pnpm people add --name "<name>" --team "<team>" prints one on ${client.host}. Someone already signed in there sees the project at once. A link signs in one device, then stops working.`,
104
+ next: `Send ${address} with each person’s own sign-in link: pnpm people add --name "<name>" prints one on ${client.host}. Someone already signed in there sees the project at once. A link signs in one device, then stops working.`,
105
105
  };
106
106
  }
107
107
  finally {
@@ -7,7 +7,7 @@ export declare const spec: {
7
7
  readonly positionals: [{
8
8
  readonly name: 'action';
9
9
  readonly required: true;
10
- readonly description: 'create: scaffold --dir, install and build it here, set it up on --team, deploy, and list it. deploy: install and build the studio folder here, so the site installs the package its package.json names, deploy it again and remove every older deployment. link: list an existing studio folder (--dir) on this machine and link it to the studio’s project.';
10
+ readonly description: 'create: scaffold --dir, install and build it here, set it up on --team, deploy, set up studio.<apex> (its DNS record and domain) and list it. deploy: install and build the studio folder here, so the site installs the package its package.json names, deploy it again, remove every older deployment, and set up studio.<apex> if it is not yet. link: list an existing studio folder (--dir) on this machine and link it to the studio’s project.';
11
11
  }];
12
12
  readonly flags: {
13
13
  readonly dir: {
@@ -28,7 +28,7 @@ export declare const spec: {
28
28
  };
29
29
  readonly owner: {
30
30
  readonly type: 'string';
31
- readonly description: 'For create: your name. You are the studio’s first Studio person and get a link on each new client’s host.';
31
+ readonly description: 'For create: your name. You are the studio’s first Studio person and get the first sign-in link, on studio.<apex>, where every client opens.';
32
32
  };
33
33
  readonly team: {
34
34
  readonly type: 'string';
@@ -69,7 +69,7 @@ export declare const spec: {
69
69
  readonly description: 'For deploy: the studio’s slug. Absent, the studio folder this runs in.';
70
70
  };
71
71
  };
72
- readonly output: 'create: { ok, studio, dir, folder, list, package, vercel, env: { GATE_SECRET: set | kept, database: created | connected | kept, files: created | kept, pulled }, mark: claimed | kept (the database marked as this studio’s), dns, owner, deployment, removed, next }. deploy: { ok, studio, package, deployment, removed }. package is what the folder’s package.json names for @milesroxas/design-hub. link: { ok, studio, dir, list, env, warnings }';
72
+ readonly output: 'create: { ok, studio, dir, folder, list, package, vercel, env: { GATE_SECRET: set | kept, database: created | connected | kept, files: created | kept, pulled }, mark: claimed | kept (the database marked as this studio’s), dns, owner, deployment, removed, studioHost: { host, state: ready | waiting, error?, fix?, record? }, link? (the owner’s, on the studio’s host, the run it first answers), next }. deploy: { ok, studio, package, deployment, removed, studioHost, link? }. The deploy is done whatever studioHost says; while it is waiting, its fix says what to do (a record to add, a certificate still coming) and the next deploy finishes it. package is what the folder’s package.json names for @milesroxas/design-hub. link: { ok, studio, dir, list, env, warnings }';
73
73
  };
74
74
  export declare function run({ positionals: [action], flags }: Args<typeof spec>, deps: StudioDeps): Promise<Record<string, unknown>>;
75
75
  export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
@@ -5,10 +5,12 @@
5
5
  //
6
6
  // studio create scaffolds the studio folder from templates/studio/,
7
7
  // installs and builds it here, sets it up on its team,
8
- // deploys it, and lists it on this machine
8
+ // deploys it, sets up the studio's own host
9
+ // (`studio.<apex>`) and lists it on this machine
9
10
  // studio deploy installs and builds the folder here and deploys it again (a
10
11
  // package upgrade reaches the site this way), then puts every
11
- // older deployment out of reach
12
+ // older deployment out of reach, and sets up the studio's
13
+ // own host if it is not yet
12
14
  // studio link lists a studio folder that already exists on this machine
13
15
  // and links it to the studio's project on its team
14
16
  //
@@ -24,9 +26,10 @@ import { claimDatabase, MarkError } from '../server/mark.js';
24
26
  import { PACKAGE, TEMPLATES } from '../server/paths.js';
25
27
  import { CliError } from './lib/cli.js';
26
28
  import { keepingGitignore } from './lib/deploy.js';
29
+ import { pointHost, waitServed } from './lib/dns.js';
27
30
  import { deployAlone } from './lib/host.js';
28
31
  import { openReview, realDeps } from './lib/studio-deps.js';
29
- import { addToList, BLOB_NAME, CLOUDFLARE_NAME, DNS_PROVIDERS, findStudio, MODE_OF, readStudio, STORE_NAMES, STUDIO_FILE, studioProblems, writeStudio, } from './lib/studios.js';
32
+ import { addToList, BLOB_NAME, CLOUDFLARE_NAME, DNS_PROVIDERS, findStudio, MODE_OF, readStudio, STORE_NAMES, STUDIO_FILE, studioHost, studioProblems, writeStudio, } from './lib/studios.js';
30
33
  export const spec = {
31
34
  name: 'studio',
32
35
  summary: 'Create a studio (its folder, its site on a Vercel team, its stores), deploy it again, or list an existing studio folder on this machine.',
@@ -34,7 +37,7 @@ export const spec = {
34
37
  {
35
38
  name: 'action',
36
39
  required: true,
37
- description: 'create: scaffold --dir, install and build it here, set it up on --team, deploy, and list it. deploy: install and build the studio folder here, so the site installs the package its package.json names, deploy it again and remove every older deployment. link: list an existing studio folder (--dir) on this machine and link it to the studio’s project.',
40
+ description: 'create: scaffold --dir, install and build it here, set it up on --team, deploy, set up studio.<apex> (its DNS record and domain) and list it. deploy: install and build the studio folder here, so the site installs the package its package.json names, deploy it again, remove every older deployment, and set up studio.<apex> if it is not yet. link: list an existing studio folder (--dir) on this machine and link it to the studio’s project.',
38
41
  },
39
42
  ],
40
43
  flags: {
@@ -50,7 +53,7 @@ export const spec = {
50
53
  },
51
54
  owner: {
52
55
  type: 'string',
53
- description: 'For create: your name. You are the studio’s first Studio person and get a link on each new client’s host.',
56
+ description: 'For create: your name. You are the studio’s first Studio person and get the first sign-in link, on studio.<apex>, where every client opens.',
54
57
  },
55
58
  team: {
56
59
  type: 'string',
@@ -88,7 +91,7 @@ export const spec = {
88
91
  description: 'For deploy: the studio’s slug. Absent, the studio folder this runs in.',
89
92
  },
90
93
  },
91
- output: 'create: { ok, studio, dir, folder, list, package, vercel, env: { GATE_SECRET: set | kept, database: created | connected | kept, files: created | kept, pulled }, mark: claimed | kept (the database marked as this studio’s), dns, owner, deployment, removed, next }. deploy: { ok, studio, package, deployment, removed }. package is what the folder’s package.json names for @milesroxas/design-hub. link: { ok, studio, dir, list, env, warnings }',
94
+ output: 'create: { ok, studio, dir, folder, list, package, vercel, env: { GATE_SECRET: set | kept, database: created | connected | kept, files: created | kept, pulled }, mark: claimed | kept (the database marked as this studio’s), dns, owner, deployment, removed, studioHost: { host, state: ready | waiting, error?, fix?, record? }, link? (the owner’s, on the studio’s host, the run it first answers), next }. deploy: { ok, studio, package, deployment, removed, studioHost, link? }. The deploy is done whatever studioHost says; while it is waiting, its fix says what to do (a record to add, a certificate still coming) and the next deploy finishes it. package is what the folder’s package.json names for @milesroxas/design-hub. link: { ok, studio, dir, list, env, warnings }',
92
95
  };
93
96
  const need = (value, flag, action) => {
94
97
  if (!value)
@@ -309,6 +312,79 @@ async function claimOrLetGo(deps, host, studio, connected) {
309
312
  });
310
313
  }
311
314
  }
315
+ /**
316
+ * The studio's own host, `studio.<apex>`, where Studio signs in and opens
317
+ * every client, set up as `client add` sets up a client's: its DNS record and
318
+ * its domain on the site, its entry in the store (which the gate reads), then
319
+ * a wait until its DNS serves it and a proof that the host answers from this
320
+ * studio's site. Only then is the owner's link made, on the run that first
321
+ * proves it; once proven, later runs leave the host alone. Each step is safe
322
+ * to repeat, so a run that stopped part way is finished by the next.
323
+ */
324
+ async function studioHostUp(deps, studio, host) {
325
+ const { config } = studio;
326
+ const name = studioHost(config.apex);
327
+ const cli = localStudio('cli', 'CLI');
328
+ const review = await openReview(deps, studio);
329
+ if (await review.studioHostProven(cli))
330
+ return { host: name, state: 'ready' };
331
+ const again = {
332
+ run: `run design-hub studio deploy --studio ${config.slug} again`,
333
+ stop: 'It prints your sign-in link once the host answers.',
334
+ };
335
+ const ensured = await pointHost(host, deps.dns(studio, host), name, again);
336
+ await review.setStudioHost(cli, name);
337
+ const proof = await review.startStudioProof(cli);
338
+ await waitServed(deps.names, config.apex, name, ensured, again);
339
+ if (!(await host.reaches(name, proof)))
340
+ throw new CliError(`${name} does not answer from the studio site yet; no sign-in link was made.`, {
341
+ ...(typeof ensured === 'object' ? { record: ensured.record } : {}),
342
+ fix: typeof ensured === 'object'
343
+ ? `Add the record at the DNS provider, then ${again.run}. ${again.stop}`
344
+ : `A new certificate can take a minute: ${again.run}. If ${name} has a DNS record of its own, another server answers it: remove that record, then ${again.run}.`,
345
+ });
346
+ await review.endStudioProof(cli);
347
+ return { host: name, state: 'ready', ...(config.owner ? { link: await ownerLink(review, config) } : {}) };
348
+ }
349
+ /**
350
+ * The studio-host step after a deploy, which is done whatever happens here:
351
+ * a step that fails (a record to add, a certificate still coming, the DNS
352
+ * token or the store missing from .env) is reported as the studio host's,
353
+ * with what to do, never as a failed deploy.
354
+ */
355
+ async function setUpStudioHost(deps, studio, host) {
356
+ try {
357
+ return await studioHostUp(deps, studio, host);
358
+ }
359
+ catch (error) {
360
+ const detail = error instanceof CliError || error instanceof MarkError ? error.detail : {};
361
+ return {
362
+ fix: `Fix what error names, then run design-hub studio deploy --studio ${studio.config.slug} again.`,
363
+ ...detail,
364
+ host: studioHost(studio.config.apex),
365
+ state: 'waiting',
366
+ error: error.message,
367
+ };
368
+ }
369
+ }
370
+ /** A new one-time link for the studio's owner, on the studio's own host. */
371
+ async function ownerLink(review, config) {
372
+ const { token } = await review.newStudioLink(localStudio('cli', 'CLI'), String(config.owner));
373
+ return `https://${studioHost(config.apex)}/invite/${token}`;
374
+ }
375
+ /**
376
+ * What `studio create` says to do next: sign in with the link; or, when the
377
+ * studio host answered on an earlier run, how to get a new link; or what the
378
+ * studio host still needs first.
379
+ */
380
+ function createNext(config, own) {
381
+ const add = `design-hub client add <client> --studio ${config.slug} --name "<client name>" --person "<their name>" --team "<their company>"`;
382
+ if (own.link)
383
+ return `Open the link to sign in at ${own.host} (it signs in one device, then stops working), then add a client: ${add}`;
384
+ if (own.state === 'ready')
385
+ return `${own.host} already answers, so no new sign-in link was made. For a new one: design-hub people link ${config.owner} --studio ${config.slug}. Add a client with: ${add}`;
386
+ return `${own.host} does not answer yet: do what studioHost.fix says, then design-hub studio deploy --studio ${config.slug} prints your sign-in link. Clients can be added meanwhile: ${add}`;
387
+ }
312
388
  async function create(flags, deps) {
313
389
  const asked = configFrom(flags);
314
390
  const owner = need(flags.owner, 'owner', 'create').trim();
@@ -335,8 +411,8 @@ async function create(flags, deps) {
335
411
  const dns = { provider: config.dns.provider, mode: config.dns.mode };
336
412
  if (config.dns.mode === 'wildcard')
337
413
  dns.wildcard = await wildcard(host, config.apex);
414
+ const review = await openReview(deps, studio);
338
415
  if (!config.owner) {
339
- const review = await openReview(deps, studio);
340
416
  const person = await review.addStudioPerson(localStudio('cli', 'CLI'), {
341
417
  name: owner,
342
418
  team: config.name,
@@ -345,6 +421,7 @@ async function create(flags, deps) {
345
421
  writeStudio(dir, config);
346
422
  }
347
423
  const deployed = await deployAlone(host);
424
+ const { link: first, ...own } = await setUpStudioHost(deps, studio, host);
348
425
  return {
349
426
  studio: config.slug,
350
427
  dir,
@@ -357,7 +434,9 @@ async function create(flags, deps) {
357
434
  dns,
358
435
  owner: config.owner,
359
436
  ...deployed,
360
- next: `design-hub client add <client> --studio ${config.slug} --name "<client name>" --person "<their name>" --team "<their company>"`,
437
+ studioHost: own,
438
+ ...(first ? { link: first } : {}),
439
+ next: createNext(config, { ...own, link: first }),
361
440
  };
362
441
  }
363
442
  async function deploy(flags, deps) {
@@ -366,7 +445,18 @@ async function deploy(flags, deps) {
366
445
  if (tgz)
367
446
  namePackage(dir, tgz);
368
447
  const pkg = installAndBuild(dir, deps);
369
- return { studio: config.slug, package: pkg, ...(await deployAlone(deps.host(dir, config))) };
448
+ const studio = { dir, config };
449
+ const host = deps.host(dir, config);
450
+ const deployed = await deployAlone(host);
451
+ // For a studio made before it had one, the owner's first link on the studio's host comes the run it answers.
452
+ const { link: first, ...own } = await setUpStudioHost(deps, studio, host);
453
+ return {
454
+ studio: config.slug,
455
+ package: pkg,
456
+ ...deployed,
457
+ studioHost: own,
458
+ ...(first ? { link: first } : {}),
459
+ };
370
460
  }
371
461
  async function link(flags, deps) {
372
462
  const dir = resolve(need(flags.dir, 'dir', 'link'));
@@ -382,7 +472,7 @@ async function link(flags, deps) {
382
472
  const pulled = await pullMissing(dir, host);
383
473
  const warnings = config.dns.provider === 'cloudflare' && !readEnv(dir)[CLOUDFLARE_NAME]
384
474
  ? [
385
- `No ${CLOUDFLARE_NAME} in .env: client add needs it. Run this again with --cloudflare-token-file <file>.`,
475
+ `No ${CLOUDFLARE_NAME} in .env: client add needs it, and studio deploy until studio.${config.apex} answers. Run this again with --cloudflare-token-file <file>.`,
386
476
  ]
387
477
  : [];
388
478
  return { studio: config.slug, dir, list, env: { pulled }, warnings };
@@ -1,6 +1,6 @@
1
1
  import type { Checks } from '../core/checks.ts';
2
- import type { Person, Scope } from '../core/review/model.ts';
3
- import { type Review } from '../core/review/service.ts';
2
+ import { type Person, type Scope } from '../core/review/model.ts';
3
+ import { type HostScope, type Review } from '../core/review/service.ts';
4
4
  import { type HostLookup } from './hosts.ts';
5
5
  import { type Gate, type GateKeys } from './session.ts';
6
6
  export declare const API_PATH = "/api/review";
@@ -10,9 +10,9 @@ export type ApiContext = {
10
10
  actor: Person | null;
11
11
  scope: Scope;
12
12
  };
13
- export declare function handleReview(request: Request, ctx: ApiContext): Promise<Response>;
14
- /** The person a request's signed cookie names, while they may still sign in, in `scope`. */
15
- export declare function actorFrom(request: Request, review: Review, gate: Gate, scope: Scope): Promise<Person | null>;
13
+ export declare const handleReview: (request: Request, ctx: ApiContext) => Promise<Response>;
14
+ /** The person a request's signed cookie names, while they may still sign in, where `at` is: a client's scope, or the studio's host. */
15
+ export declare function actorFrom(request: Request, review: Review, gate: Gate, at: HostScope): Promise<Person | null>;
16
16
  /** A studio site's review service and gate keys, or why it has none. */
17
17
  export type Deployed = {
18
18
  review: Review;
@@ -30,8 +30,6 @@ export type Deployed = {
30
30
  export declare function studioReview(env: Record<string, string | undefined>, checks?: Checks | null, now?: () => Date): Deployed;
31
31
  /**
32
32
  * A studio site's review function: the host's client is the scope, and the
33
- * gate's client, of every op. The session is read before any project is
34
- * looked up (S5), so a caller signed out, or signed in for another client,
35
- * gets one answer whatever project the request names.
33
+ * gate's client, of every op; the studio's own host has the studio hub's.
36
34
  */
37
35
  export declare function studioHandler(request: Request, checks: Checks | null, hosts: HostLookup): Promise<Response>;