@milesroxas/design-hub 0.11.2 → 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.
- package/README.md +4 -2
- package/core/prototype.test.ts +52 -0
- package/core/prototype.ts +59 -0
- package/core/review/model.ts +20 -0
- package/core/review/service.test.ts +224 -0
- package/core/review/service.ts +276 -52
- package/core/review/store.ts +10 -4
- package/dist/core/prototype.d.ts +50 -0
- package/dist/core/prototype.js +38 -0
- package/dist/core/review/model.d.ts +22 -0
- package/dist/core/review/model.js +8 -0
- package/dist/core/review/service.d.ts +98 -18
- package/dist/core/review/service.js +248 -46
- package/dist/core/review/store.d.ts +10 -4
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +52 -66
- package/dist/scripts/lib/dns.d.ts +32 -0
- package/dist/scripts/lib/dns.js +69 -1
- package/dist/scripts/lib/fake-host.d.ts +34 -9
- package/dist/scripts/lib/fake-host.js +7 -4
- package/dist/scripts/lib/studios.d.ts +3 -1
- package/dist/scripts/lib/studios.js +2 -0
- package/dist/scripts/people.d.ts +7 -4
- package/dist/scripts/people.js +147 -39
- package/dist/scripts/studio.d.ts +3 -3
- package/dist/scripts/studio.js +100 -10
- package/dist/server/api.d.ts +6 -8
- package/dist/server/api.js +129 -42
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/session.d.ts +7 -0
- package/dist/server/session.js +8 -1
- package/dist/vercel/proxy.d.ts +7 -3
- package/dist/vercel/proxy.js +215 -49
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +21 -3
- package/package.json +1 -1
- package/shell/Index.tsx +29 -0
- package/shell/review/People.tsx +79 -49
- package/shell/review/Review.tsx +49 -1
- package/shell/review/ThreadCard.tsx +13 -1
- package/shell/review/client.ts +54 -21
- package/shell/review/review.css +1 -0
- package/shell/review/unsent.test.ts +63 -0
- package/shell/review/unsent.ts +64 -0
- package/shell/review/view.ts +22 -6
- package/shell/studio/ClientHub.tsx +9 -36
- package/shell/studio/StudioHub.tsx +293 -0
- package/shell/studio/hub.css +80 -5
- package/shell/studio/page.tsx +57 -0
- package/shell/studio/studio.html +14 -0
- package/shell/studio/studio.tsx +19 -0
- package/skills/miles-deploy/SKILL.md +15 -5
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/README.md +32 -13
- package/templates/studio/package.json +1 -1
package/dist/scripts/people.js
CHANGED
|
@@ -2,21 +2,29 @@
|
|
|
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
|
|
6
|
-
// needs a new link. Studio
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
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';
|
|
17
|
+
import { readLink, realProjectDeps } from './lib/linked.js';
|
|
12
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
|
|
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
|
],
|
|
@@ -28,23 +36,26 @@ export const spec = {
|
|
|
28
36
|
},
|
|
29
37
|
kind: {
|
|
30
38
|
type: 'string',
|
|
31
|
-
default: 'client',
|
|
32
39
|
choices: PERSON_KINDS,
|
|
33
|
-
description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and
|
|
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.',
|
|
34
41
|
},
|
|
35
42
|
access: {
|
|
36
43
|
type: 'string',
|
|
37
44
|
choices: ACCESS,
|
|
38
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.',
|
|
39
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
|
+
},
|
|
40
51
|
local: {
|
|
41
52
|
type: 'boolean',
|
|
42
53
|
description: 'Use this machine’s dev store, even in a project linked to a studio.',
|
|
43
54
|
},
|
|
44
55
|
},
|
|
45
|
-
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.',
|
|
46
57
|
};
|
|
47
|
-
/** A link on the
|
|
58
|
+
/** A link on the host it signs in on; a local one is a path the dev server never asks for. */
|
|
48
59
|
const linkFor = (token, host) => {
|
|
49
60
|
const path = `/invite/${token}`;
|
|
50
61
|
if (!host)
|
|
@@ -60,55 +71,152 @@ function needId(action, id) {
|
|
|
60
71
|
throw new CliError(`Name the person: pnpm people ${action} <id>.`, { fix: 'pnpm people lists ids.' });
|
|
61
72
|
return id;
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
person: strip(r.person),
|
|
65
|
-
|
|
66
|
-
});
|
|
74
|
+
async function withLink(r, c) {
|
|
75
|
+
return { person: strip(r.person), ...linkFor(r.token, await c.hostFor(r.person)) };
|
|
76
|
+
}
|
|
67
77
|
/** One person's access with an id, else the default for a new Client: read it, or set it with --access. */
|
|
68
|
-
async function access({ review,
|
|
78
|
+
async function access({ review, at, actor, flags, id }) {
|
|
69
79
|
if (id) {
|
|
70
80
|
if (!flags.access)
|
|
71
81
|
throw new CliError('Say how long: pnpm people access <id> --access 3m|6m|open.');
|
|
72
|
-
return { person: strip(await review.setAccess(
|
|
82
|
+
return { person: strip(await review.setAccess(at, actor, id, flags.access)) };
|
|
73
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
|
+
};
|
|
74
90
|
return {
|
|
75
91
|
access: flags.access
|
|
76
|
-
? await review.setDefaultAccess(
|
|
77
|
-
: await review.defaultAccess(
|
|
92
|
+
? await review.setDefaultAccess(at, actor, flags.access)
|
|
93
|
+
: await review.defaultAccess(at, actor),
|
|
78
94
|
};
|
|
79
95
|
}
|
|
80
|
-
/** What adding a Studio person
|
|
81
|
-
const studioWide = ({ studio, 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']);
|
|
82
100
|
const ACTIONS = {
|
|
83
|
-
list: async ({ review,
|
|
84
|
-
add: async (
|
|
85
|
-
name: flags.name,
|
|
86
|
-
team: flags.team,
|
|
87
|
-
kind: flags.kind,
|
|
88
|
-
access: flags.access,
|
|
89
|
-
}),
|
|
90
|
-
link: async (
|
|
91
|
-
'sign-out': async (
|
|
92
|
-
revoke: async ({ review,
|
|
93
|
-
person: strip(await review.revoke(
|
|
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))),
|
|
94
112
|
}),
|
|
95
113
|
access,
|
|
96
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
|
+
}
|
|
97
186
|
export async function run({ positionals: [action = 'list', id], flags }, deps) {
|
|
98
187
|
const act = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
|
|
99
188
|
if (!act)
|
|
100
189
|
throw new CliError(`Unknown action ${action}.`, { fix: 'list, add, link, sign-out, revoke or access' });
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
const
|
|
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;
|
|
105
199
|
return {
|
|
106
200
|
store,
|
|
107
|
-
...(
|
|
201
|
+
...(studio ? { studio } : {}),
|
|
108
202
|
...done,
|
|
109
|
-
...(
|
|
110
|
-
? { notice: studioWide(
|
|
203
|
+
...(studioAdded
|
|
204
|
+
? { notice: studioWide(project, String(done.link)) }
|
|
111
205
|
: {}),
|
|
112
206
|
};
|
|
113
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
|
+
}
|
|
114
222
|
export const main = (args) => run(args, realProjectDeps());
|
package/dist/scripts/studio.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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>>;
|
package/dist/scripts/studio.js
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
package/dist/server/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Checks } from '../core/checks.ts';
|
|
2
|
-
import type
|
|
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
|
|
14
|
-
/** The person a request's signed cookie names, while they may still sign in,
|
|
15
|
-
export declare function actorFrom(request: Request, review: Review, gate: Gate,
|
|
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
|
|
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>;
|