@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
|
@@ -24,15 +24,19 @@ export interface KV {
|
|
|
24
24
|
/**
|
|
25
25
|
* The studio's own records: Studio people (profile, revocation, epoch and
|
|
26
26
|
* links, as a client's below) and `settings`, one field each: `access` is the
|
|
27
|
-
* default access length
|
|
27
|
+
* default access length, `hostProvenAt` when the studio's own host first
|
|
28
|
+
* answered its proof. `proof`: while a command waits for the studio's own
|
|
29
|
+
* host, one field, hex(sha256(ask)) to the answer the gate gives there.
|
|
30
|
+
* `mark`, one field, `id`: the id of the one studio
|
|
28
31
|
* this database serves (its studio.json `id`), set once by `studio create`
|
|
29
32
|
* and checked by every command before it acts (server/mark.ts). No other
|
|
30
33
|
* key names a studio, so two studios on one database would be one studio.
|
|
31
34
|
*/
|
|
32
|
-
type StudioName = 'people' | 'revoked' | 'epochs' | 'links' | 'settings' | 'mark';
|
|
35
|
+
type StudioName = 'people' | 'revoked' | 'epochs' | 'links' | 'settings' | 'mark' | 'proof';
|
|
33
36
|
/**
|
|
34
37
|
* The studio's clients, outside every scope: `clients`, a client's slug to
|
|
35
|
-
* its Client; `hosts`, a host name to the slug of the client it serves
|
|
38
|
+
* its Client; `hosts`, a host name to the slug of the client it serves, or
|
|
39
|
+
* to `studio` (STUDIO_SITE) for the studio's own host, which no client slug is;
|
|
36
40
|
* `claims`, one counter per slug (`client:<slug>`) and per host
|
|
37
41
|
* (`host:<host>`), raised by HINCRBY when a client is added: whoever raised
|
|
38
42
|
* it to 1 holds it, so two adds at once never both get one. Archiving a
|
|
@@ -51,9 +55,11 @@ type DirectoryName = 'clients' | 'hosts' | 'claims' | 'held';
|
|
|
51
55
|
* `projects`: the client's projects, a slug to its Project. `proof`: while
|
|
52
56
|
* `client add` waits for the client's host, one field, hex(sha256(ask)) to
|
|
53
57
|
* the answer the gate gives for that ask (PROOF_PATH in prototype.ts).
|
|
58
|
+
* `handoffs`: Studio opening this client from the studio's host,
|
|
59
|
+
* hex(sha256(token)) to a Handoff, deleted when the client's host claims it.
|
|
54
60
|
*/
|
|
55
61
|
type ClientName = 'people' | 'revoked' | 'epochs' | 'links';
|
|
56
|
-
type ClientOnlyName = 'projects' | 'proof';
|
|
62
|
+
type ClientOnlyName = 'projects' | 'proof' | 'handoffs';
|
|
57
63
|
/**
|
|
58
64
|
* A project's records. `audiences`: which prototypes are client-facing,
|
|
59
65
|
* field `<slug>`, value `client`; only client-facing is stored, internal is
|
package/dist/scripts/client.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { type Args } from './lib/cli.ts';
|
|
|
3
3
|
import { type StudioDeps } from './lib/studio-deps.ts';
|
|
4
4
|
export declare const spec: {
|
|
5
5
|
readonly name: 'client';
|
|
6
|
-
readonly summary: 'Add a client to a studio with its host and first sign-in
|
|
6
|
+
readonly summary: 'Add a client to a studio with its host and its first person’s sign-in link, archive one, list them, or set how long its people keep access.';
|
|
7
7
|
readonly positionals: [{
|
|
8
8
|
readonly name: 'action';
|
|
9
9
|
readonly required: true;
|
|
10
|
-
readonly description: 'add <slug>: the client, its host and its first
|
|
10
|
+
readonly description: 'add <slug>: the client, its host and its first person’s link (Studio opens it from studio.<apex>). list: every client, with its host, state and project count. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.';
|
|
11
11
|
}, {
|
|
12
12
|
readonly name: 'slug';
|
|
13
13
|
readonly description: 'The client, kebab-case; never studio, www, api or site.';
|
|
@@ -39,7 +39,7 @@ export declare const spec: {
|
|
|
39
39
|
readonly description: 'For access: 3m, 6m or open; with a slug, studio hands the client back to the studio’s default. A person’s own length wins over both.';
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
readonly output: 'add: { ok, client, host, dns, links: { client
|
|
42
|
+
readonly output: 'add: { ok, client, host, dns, links: { client }, notice?, next }. list: { ok, clients: [{ slug, name, host, state: added | waiting | archived, projects }] } (waiting: its add has not finished; archived: its archive has not finished). archive: { ok, client, host, domain: removed | absent | wildcard | kept (another client has the host) | unknown, files, dns?: { removed, left, fix? } | { record, fix } }. access: { ok, client?, access, default }';
|
|
43
43
|
};
|
|
44
44
|
export declare function run({ positionals: [action, slug], flags }: Args<typeof spec>, deps: StudioDeps): Promise<Record<string, unknown>>;
|
|
45
45
|
export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
|
package/dist/scripts/client.js
CHANGED
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
//
|
|
6
6
|
// client add <slug> its host (DNS record and domain) and the client,
|
|
7
7
|
// then, once the host proves it is this studio's
|
|
8
|
-
// site, its first sign-in
|
|
8
|
+
// site, its first person's sign-in link, on that host only
|
|
9
9
|
// client archive <slug> every key and file it has, so the slug used again
|
|
10
10
|
// starts clean, then its DNS record (one this studio
|
|
11
11
|
// made) and its host off the site
|
|
12
12
|
// client access [slug] how long a new person of the client keeps access
|
|
13
13
|
// (the studio's default without a slug)
|
|
14
|
+
// client list every client: its host, whether it is added, and
|
|
15
|
+
// how many projects it has
|
|
14
16
|
//
|
|
15
17
|
// No link exists until the host proves it: asked over HTTPS for a proof the
|
|
16
18
|
// store holds, it must send back the answer only this studio's gate can give,
|
|
17
|
-
// so a host another server answers never gets one.
|
|
19
|
+
// so a host another server answers never gets one. Studio people open a
|
|
20
|
+
// client from the studio's own host (a handoff), so no Studio link is made here. Nothing asks for the host
|
|
18
21
|
// through this machine's resolver until the zone's own nameservers serve it,
|
|
19
22
|
// so no resolver is left keeping "no such host" for it. A run that stops part way
|
|
20
23
|
// (a record to add, a certificate still coming) leaves the client waiting for
|
|
@@ -24,18 +27,19 @@ import { ACCESS, isAdded, isStudioClient, STUDIO_CLIENT_SLUG } from '../core/rev
|
|
|
24
27
|
import { REUSE_SECONDS } from '../core/review/service.js';
|
|
25
28
|
import { localStudio } from '../server/local.js';
|
|
26
29
|
import { CliError } from './lib/cli.js';
|
|
30
|
+
import { pointHost, waitServed } from './lib/dns.js';
|
|
27
31
|
import { openReview, realDeps, recordOf } from './lib/studio-deps.js';
|
|
28
|
-
import { clientHost, findStudio } from './lib/studios.js';
|
|
32
|
+
import { clientHost, findStudio, studioHost } from './lib/studios.js';
|
|
29
33
|
/** S9: what a per-host or manual record makes public. */
|
|
30
34
|
const PUBLIC_HOST = 'With per-host DNS a client’s host is public in certificate logs from the moment it is added. To keep the client’s name out of them, add it with --host <codename>.';
|
|
31
35
|
export const spec = {
|
|
32
36
|
name: 'client',
|
|
33
|
-
summary: 'Add a client to a studio with its host and first sign-in
|
|
37
|
+
summary: 'Add a client to a studio with its host and its first person’s sign-in link, archive one, list them, or set how long its people keep access.',
|
|
34
38
|
positionals: [
|
|
35
39
|
{
|
|
36
40
|
name: 'action',
|
|
37
41
|
required: true,
|
|
38
|
-
description: 'add <slug>: the client, its host and its first
|
|
42
|
+
description: 'add <slug>: the client, its host and its first person’s link (Studio opens it from studio.<apex>). list: every client, with its host, state and project count. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.',
|
|
39
43
|
},
|
|
40
44
|
{ name: 'slug', description: 'The client, kebab-case; never studio, www, api or site.' },
|
|
41
45
|
],
|
|
@@ -60,9 +64,12 @@ export const spec = {
|
|
|
60
64
|
description: 'For access: 3m, 6m or open; with a slug, studio hands the client back to the studio’s default. A person’s own length wins over both.',
|
|
61
65
|
},
|
|
62
66
|
},
|
|
63
|
-
output: 'add: { ok, client, host, dns, links: { client
|
|
67
|
+
output: 'add: { ok, client, host, dns, links: { client }, notice?, next }. list: { ok, clients: [{ slug, name, host, state: added | waiting | archived, projects }] } (waiting: its add has not finished; archived: its archive has not finished). archive: { ok, client, host, domain: removed | absent | wildcard | kept (another client has the host) | unknown, files, dns?: { removed, left, fix? } | { record, fix } }. access: { ok, client?, access, default }',
|
|
64
68
|
};
|
|
65
69
|
const actor = () => localStudio('cli', 'CLI');
|
|
70
|
+
/** What `client add` says to run again, and how to drop a client being added instead. */
|
|
71
|
+
const SAME_FLAGS = 'run this again with the same flags';
|
|
72
|
+
const dropIt = (studio, slug) => `To drop it instead: design-hub client archive ${slug} --studio ${studio.config.slug}.`;
|
|
66
73
|
function needSlug(action, slug) {
|
|
67
74
|
if (!slug)
|
|
68
75
|
throw new CliError(`Name the client: design-hub client ${action} <slug>.`);
|
|
@@ -107,56 +114,6 @@ async function free({ review, flags, studio }, slug, host) {
|
|
|
107
114
|
throw new CliError(`${host} already serves a client.`, { fix: 'Pick another --host.' });
|
|
108
115
|
return null;
|
|
109
116
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Points the host at the studio site: its DNS record and, unless the
|
|
112
|
-
* wildcard serves it, its domain on the project (verified). Each step is safe
|
|
113
|
-
* to repeat; one a person must take stops the command with what to do.
|
|
114
|
-
*/
|
|
115
|
-
async function serve(host, dns, name) {
|
|
116
|
-
const ensured = await dns.ensure(name);
|
|
117
|
-
if (dns.mode !== 'wildcard') {
|
|
118
|
-
const domain = await host.addDomain(name);
|
|
119
|
-
if (!domain.verified)
|
|
120
|
-
throw new CliError(`Vercel asks for proof that the studio may use ${name}.`, {
|
|
121
|
-
records: domain.verification.map((v) => `${v.type} ${v.domain} ${v.value}`),
|
|
122
|
-
fix: 'Add each record at the DNS provider, then run this again with the same flags.',
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return ensured;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Holds every request for the host back until its DNS serves it. A resolver
|
|
129
|
-
* asked for a name in the seconds before its record is served keeps "no such
|
|
130
|
-
* host" for the zone's negative-cache time, for this machine and everyone
|
|
131
|
-
* behind it; so the host is first asked only of its zone's own nameservers,
|
|
132
|
-
* which never cache, and this machine's resolver once they all serve it. One
|
|
133
|
-
* that already keeps a miss, from before this command or an earlier run,
|
|
134
|
-
* stops it with what to wait for: the proof is never skipped, and without
|
|
135
|
-
* that resolver it cannot be asked.
|
|
136
|
-
*/
|
|
137
|
-
async function served(ctx, host, ensured, stop) {
|
|
138
|
-
const { state, zone, negative } = await ctx.deps.names.served(host, ctx.studio.config.apex);
|
|
139
|
-
const record = typeof ensured === 'object' ? { record: ensured.record } : {};
|
|
140
|
-
if (state === 'unreachable')
|
|
141
|
-
throw new CliError(`This network would not let the command ask the nameservers of ${zone ?? ctx.studio.config.apex} whether ${host} is served; no sign-in link was made.`, {
|
|
142
|
-
...record,
|
|
143
|
-
fix: `Run this again with the same flags on a network that lets DNS through to any server. ${stop}`,
|
|
144
|
-
});
|
|
145
|
-
if (state === 'missing')
|
|
146
|
-
throw new CliError(`${host} is not served by its DNS yet; no sign-in link was made.`, {
|
|
147
|
-
...record,
|
|
148
|
-
fix: typeof ensured === 'object'
|
|
149
|
-
? `Add the record at the DNS provider, then run this again with the same flags. ${stop}`
|
|
150
|
-
: `A new record can take a minute to be served: run this again with the same flags. ${stop}`,
|
|
151
|
-
});
|
|
152
|
-
if (await ctx.deps.names.seen(host))
|
|
153
|
-
return;
|
|
154
|
-
const within = negative ? `up to ${Math.ceil(negative / 60)} minutes` : 'some minutes';
|
|
155
|
-
throw new CliError(`${host} is set up, and its DNS serves it, but this network does not see it yet; no sign-in link was made.`, {
|
|
156
|
-
...(negative ? { wait: negative } : {}),
|
|
157
|
-
fix: `Nothing is left to set up. This network's resolver keeps an earlier "no such host" for ${within} (the zone's negative-cache time); run this again with the same flags once that has passed. ${stop}`,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
117
|
/**
|
|
161
118
|
* Proves, before any link exists, that the client's host is this studio's
|
|
162
119
|
* site: a new proof in the store, whose answer the host must send back for
|
|
@@ -169,8 +126,8 @@ async function prove(ctx, host, client, ensured) {
|
|
|
169
126
|
const { review } = ctx;
|
|
170
127
|
const scope = { client: client.slug };
|
|
171
128
|
const proof = await review.startProof(scope, actor());
|
|
172
|
-
const stop =
|
|
173
|
-
await
|
|
129
|
+
const stop = dropIt(ctx.studio, client.slug);
|
|
130
|
+
await waitServed(ctx.deps.names, ctx.studio.config.apex, client.host, ensured, { run: SAME_FLAGS, stop });
|
|
174
131
|
if (await host.reaches(client.host, proof)) {
|
|
175
132
|
await review.endProof(scope, actor());
|
|
176
133
|
return;
|
|
@@ -182,6 +139,13 @@ async function prove(ctx, host, client, ensured) {
|
|
|
182
139
|
: `A new certificate can take a minute: run this again with the same flags. If ${client.host} has a DNS record of its own, another server answers it: remove that record, or archive the client and add it with another --host. ${stop}`,
|
|
183
140
|
});
|
|
184
141
|
}
|
|
142
|
+
/** Where Studio opens the client: the studio's own host, or, for a studio not deployed since it had one, what sets it up. */
|
|
143
|
+
async function whereStudioOpens(review, { config }) {
|
|
144
|
+
const own = studioHost(config.apex);
|
|
145
|
+
return (await review.studioHostProven(actor()))
|
|
146
|
+
? `You open the client from ${own}.`
|
|
147
|
+
: `You open clients from ${own}, which is not set up yet: run design-hub studio deploy --studio ${config.slug} first.`;
|
|
148
|
+
}
|
|
185
149
|
async function add(ctx) {
|
|
186
150
|
const { studio, review, deps, flags } = ctx;
|
|
187
151
|
const slug = needSlug('add', ctx.slug);
|
|
@@ -193,9 +157,13 @@ async function add(ctx) {
|
|
|
193
157
|
const name = clientHost(slug, config.apex, flags.host);
|
|
194
158
|
const waiting = await free(ctx, slug, name);
|
|
195
159
|
const host = deps.host(studio.dir, config);
|
|
196
|
-
const dns = await
|
|
160
|
+
const dns = await pointHost(host, deps.dns(studio, host), name, {
|
|
161
|
+
run: SAME_FLAGS,
|
|
162
|
+
stop: dropIt(studio, slug),
|
|
163
|
+
instead: 'Or add the client with another --host.',
|
|
164
|
+
});
|
|
197
165
|
// The client goes in before the host is asked anything, so the gate never keeps the host as unknown
|
|
198
|
-
// (server/hosts.ts) and the
|
|
166
|
+
// (server/hosts.ts) and the link opens at once; nobody can sign in until the proof passes.
|
|
199
167
|
const client = waiting ?? (await review.addClient(actor(), { slug, host: name, name: flags.name }));
|
|
200
168
|
// Its files start clean too, now the slug is its own: whatever a share that raced an archive of an
|
|
201
169
|
// earlier client of the slug left. Again on a run that finishes one, in case the last stopped first;
|
|
@@ -212,18 +180,17 @@ async function add(ctx) {
|
|
|
212
180
|
team: flags.team ?? flags.name,
|
|
213
181
|
kind: 'client',
|
|
214
182
|
});
|
|
215
|
-
const studioLink = config.owner ? await review.newStudioLink(actor(), config.owner) : null;
|
|
216
183
|
return {
|
|
217
184
|
client: { slug: client.slug, name: client.name },
|
|
218
185
|
host: client.host,
|
|
219
186
|
dns,
|
|
220
|
-
links: { client: at(first.token)
|
|
187
|
+
links: { client: at(first.token) },
|
|
221
188
|
...(config.dns.mode === 'wildcard' ? {} : { notice: PUBLIC_HOST }),
|
|
222
|
-
next:
|
|
189
|
+
next: `Send the link to ${flags.person}. It signs in one device on this host, then stops working; one that shows Not found opens within a minute, since the site keeps a host’s answer that long. ${await whereStudioOpens(review, studio)}`,
|
|
223
190
|
};
|
|
224
191
|
}
|
|
225
192
|
catch (error) {
|
|
226
|
-
throw new CliError(`Client ${slug} was added, but its first
|
|
193
|
+
throw new CliError(`Client ${slug} was added, but its first link was not: ${error.message}`, {
|
|
227
194
|
fix: `design-hub client archive ${slug} --studio ${config.slug}, then add it again.`,
|
|
228
195
|
});
|
|
229
196
|
}
|
|
@@ -309,11 +276,30 @@ async function access({ review, flags, slug }) {
|
|
|
309
276
|
default: await review.defaultAccess(scope, actor()),
|
|
310
277
|
};
|
|
311
278
|
}
|
|
312
|
-
|
|
279
|
+
/** What `list` says of a client's state: added, still being added, or archived with its archive not finished. */
|
|
280
|
+
const stateOf = (c) => (c.archivedAt !== null ? 'archived' : isAdded(c) ? 'added' : 'waiting');
|
|
281
|
+
async function list({ review }) {
|
|
282
|
+
const clients = await review.listClients(actor());
|
|
283
|
+
return {
|
|
284
|
+
clients: clients.map(({ client, projects }) => ({
|
|
285
|
+
slug: client.slug,
|
|
286
|
+
name: client.name,
|
|
287
|
+
host: client.host,
|
|
288
|
+
state: stateOf(client),
|
|
289
|
+
projects: projects.length,
|
|
290
|
+
})),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const ACTIONS = {
|
|
294
|
+
add,
|
|
295
|
+
archive,
|
|
296
|
+
access,
|
|
297
|
+
list,
|
|
298
|
+
};
|
|
313
299
|
export async function run({ positionals: [action, slug], flags }, deps) {
|
|
314
300
|
const act = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
|
|
315
301
|
if (!act)
|
|
316
|
-
throw new CliError(`Unknown action ${action}.`, { fix: 'add, archive or
|
|
302
|
+
throw new CliError(`Unknown action ${action}.`, { fix: 'add, archive, access or list' });
|
|
317
303
|
const studio = findStudio(deps.home, flags.studio, deps.cwd);
|
|
318
304
|
return act({ studio, review: await openReview(deps, studio), deps, flags, slug });
|
|
319
305
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Host } from './host.ts';
|
|
2
|
+
import type { Names } from './names.ts';
|
|
1
3
|
import type { DnsMode } from './studios.ts';
|
|
2
4
|
export type Ensured = 'added' | 'exists' | {
|
|
3
5
|
record: string;
|
|
@@ -15,6 +17,36 @@ export interface Dns {
|
|
|
15
17
|
/** Takes the host's record off, once its client is archived: only one this studio made. */
|
|
16
18
|
release(host: string): Promise<Released>;
|
|
17
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* How a command that sets up a host says what to do next: `run` is the
|
|
22
|
+
* command to run again ("run this again with the same flags"), `stop` the
|
|
23
|
+
* sentence after it, and `instead` what else a person may do about a host
|
|
24
|
+
* that already has records (`client add` takes another --host).
|
|
25
|
+
*/
|
|
26
|
+
export type Again = {
|
|
27
|
+
run: string;
|
|
28
|
+
stop: string;
|
|
29
|
+
instead?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Points a host at the studio site: its DNS record and, unless the wildcard
|
|
33
|
+
* serves it, its domain on the project (verified). Each step is safe to
|
|
34
|
+
* repeat, so a run that stopped part way is finished by the next one; one a
|
|
35
|
+
* person must take stops the command with what to do. A client's host and
|
|
36
|
+
* the studio's own host are set up the same way.
|
|
37
|
+
*/
|
|
38
|
+
export declare function pointHost(host: Host, dns: Dns, name: string, again: Again): Promise<Ensured>;
|
|
39
|
+
/**
|
|
40
|
+
* Holds every request for the host back until its DNS serves it. A resolver
|
|
41
|
+
* asked for a name in the seconds before its record is served keeps "no such
|
|
42
|
+
* host" for the zone's negative-cache time, for this machine and everyone
|
|
43
|
+
* behind it; so the host is first asked only of its zone's own nameservers,
|
|
44
|
+
* which never cache, and this machine's resolver once they all serve it. One
|
|
45
|
+
* that already keeps a miss, from before this command or an earlier run,
|
|
46
|
+
* stops it with what to wait for: the proof is never skipped, and without
|
|
47
|
+
* that resolver it cannot be asked.
|
|
48
|
+
*/
|
|
49
|
+
export declare function waitServed(names: Names, apex: string, host: string, ensured: Ensured, { run, stop }: Again): Promise<void>;
|
|
18
50
|
/** Where a host should point, from the host port (Vercel's first-ranked CNAME for it). */
|
|
19
51
|
type Target = (host: string) => Promise<string>;
|
|
20
52
|
/** The wildcard serves every host and stays: nothing to add or remove per host. */
|
package/dist/scripts/lib/dns.js
CHANGED
|
@@ -14,6 +14,71 @@
|
|
|
14
14
|
// gitignored `.env` and is sent only in the Authorization header; no error
|
|
15
15
|
// here repeats it.
|
|
16
16
|
import { CliError } from './cli.js';
|
|
17
|
+
const cap = (text) => text.charAt(0).toUpperCase() + text.slice(1);
|
|
18
|
+
/**
|
|
19
|
+
* Points a host at the studio site: its DNS record and, unless the wildcard
|
|
20
|
+
* serves it, its domain on the project (verified). Each step is safe to
|
|
21
|
+
* repeat, so a run that stopped part way is finished by the next one; one a
|
|
22
|
+
* person must take stops the command with what to do. A client's host and
|
|
23
|
+
* the studio's own host are set up the same way.
|
|
24
|
+
*/
|
|
25
|
+
export async function pointHost(host, dns, name, again) {
|
|
26
|
+
const ensured = await ensureNamed(dns, name, again);
|
|
27
|
+
if (dns.mode !== 'wildcard') {
|
|
28
|
+
const domain = await host.addDomain(name);
|
|
29
|
+
if (!domain.verified)
|
|
30
|
+
throw new CliError(`Vercel asks for proof that the studio may use ${name}.`, {
|
|
31
|
+
records: domain.verification.map((v) => `${v.type} ${v.domain} ${v.value}`),
|
|
32
|
+
fix: `Add each record at the DNS provider, then ${again.run}.`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return ensured;
|
|
36
|
+
}
|
|
37
|
+
/** The DNS port's ensure, a host already holding records named in the words of the host it is for. */
|
|
38
|
+
async function ensureNamed(dns, name, again) {
|
|
39
|
+
try {
|
|
40
|
+
return await dns.ensure(name);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (!(error instanceof CliError) || error.detail.code !== 'dns_taken')
|
|
44
|
+
throw error;
|
|
45
|
+
const { found, target } = error.detail;
|
|
46
|
+
throw new CliError(`${name} already has DNS records this studio did not make; nothing was changed there.`, {
|
|
47
|
+
found,
|
|
48
|
+
fix: `Point ${name} at ${target} with one DNS-only CNAME at Cloudflare, or remove its records, then ${again.run}.${again.instead ? ` ${again.instead}` : ''}`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Holds every request for the host back until its DNS serves it. A resolver
|
|
54
|
+
* asked for a name in the seconds before its record is served keeps "no such
|
|
55
|
+
* host" for the zone's negative-cache time, for this machine and everyone
|
|
56
|
+
* behind it; so the host is first asked only of its zone's own nameservers,
|
|
57
|
+
* which never cache, and this machine's resolver once they all serve it. One
|
|
58
|
+
* that already keeps a miss, from before this command or an earlier run,
|
|
59
|
+
* stops it with what to wait for: the proof is never skipped, and without
|
|
60
|
+
* that resolver it cannot be asked.
|
|
61
|
+
*/
|
|
62
|
+
export async function waitServed(names, apex, host, ensured, { run, stop }) {
|
|
63
|
+
const { state, zone, negative } = await names.served(host, apex);
|
|
64
|
+
const record = typeof ensured === 'object' ? { record: ensured.record } : {};
|
|
65
|
+
if (state === 'unreachable')
|
|
66
|
+
throw new CliError(`This network would not let the command ask the nameservers of ${zone ?? apex} whether ${host} is served; no sign-in link was made.`, { ...record, fix: `${cap(run)} on a network that lets DNS through to any server. ${stop}` });
|
|
67
|
+
if (state === 'missing')
|
|
68
|
+
throw new CliError(`${host} is not served by its DNS yet; no sign-in link was made.`, {
|
|
69
|
+
...record,
|
|
70
|
+
fix: typeof ensured === 'object'
|
|
71
|
+
? `Add the record at the DNS provider, then ${run}. ${stop}`
|
|
72
|
+
: `A new record can take a minute to be served: ${run}. ${stop}`,
|
|
73
|
+
});
|
|
74
|
+
if (await names.seen(host))
|
|
75
|
+
return;
|
|
76
|
+
const within = negative ? `up to ${Math.ceil(negative / 60)} minutes` : 'some minutes';
|
|
77
|
+
throw new CliError(`${host} is set up, and its DNS serves it, but this network does not see it yet; no sign-in link was made.`, {
|
|
78
|
+
...(negative ? { wait: negative } : {}),
|
|
79
|
+
fix: `Nothing is left to set up. This network's resolver keeps an earlier "no such host" for ${within} (the zone's negative-cache time); ${run} once that has passed. ${stop}`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
17
82
|
/** The wildcard serves every host and stays: nothing to add or remove per host. */
|
|
18
83
|
export const wildcardDns = () => ({
|
|
19
84
|
mode: 'wildcard',
|
|
@@ -45,9 +110,12 @@ export function classify(found, target) {
|
|
|
45
110
|
only.proxied !== true;
|
|
46
111
|
if (ok)
|
|
47
112
|
return 'exists';
|
|
113
|
+
// pointHost names the host and what to run again; this says only what is there.
|
|
48
114
|
throw new CliError('The host already has DNS records this studio did not make.', {
|
|
115
|
+
code: 'dns_taken',
|
|
49
116
|
found: found.map((r) => ({ type: r.type, content: r.content, proxied: r.proxied ?? false })),
|
|
50
|
-
|
|
117
|
+
target,
|
|
118
|
+
fix: `Point it at ${target} with one DNS-only CNAME at Cloudflare.`,
|
|
51
119
|
});
|
|
52
120
|
}
|
|
53
121
|
export function cloudflareDns({ token, apex, zone, studio, target, fetcher = fetch, }) {
|
|
@@ -43,6 +43,31 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
43
43
|
review: {
|
|
44
44
|
person: (scope: import("../../core/review/model.ts").Scope, id: string) => Promise<import("../../core/review/model.ts").Person | null>;
|
|
45
45
|
clientOfHost(host: string): Promise<import("../../core/review/model.ts").Client | null>;
|
|
46
|
+
siteOfHost: (host: string) => Promise<import("../../core/review/model.ts").Site>;
|
|
47
|
+
studioHostProven(actor: import("../../core/review/model.ts").Person | null): Promise<boolean>;
|
|
48
|
+
startStudioProof(actor: import("../../core/review/model.ts").Person | null): Promise<{
|
|
49
|
+
ask: string;
|
|
50
|
+
answer: string;
|
|
51
|
+
}>;
|
|
52
|
+
endStudioProof(actor: import("../../core/review/model.ts").Person | null): Promise<void>;
|
|
53
|
+
studioProofAnswer(ask: string): Promise<string | null>;
|
|
54
|
+
setStudioHost(actor: import("../../core/review/model.ts").Person | null, host: string): Promise<'added' | 'kept'>;
|
|
55
|
+
listClients(actor: import("../../core/review/model.ts").Person | null): Promise<{
|
|
56
|
+
client: import("../../core/review/model.ts").Client;
|
|
57
|
+
projects: import("../../core/review/model.ts").Project[];
|
|
58
|
+
}[]>;
|
|
59
|
+
studioClient(actor: import("../../core/review/model.ts").Person | null, slug: unknown): Promise<import("../../core/review/model.ts").Client>;
|
|
60
|
+
startHandoff(actor: import("../../core/review/model.ts").Person | null, input: {
|
|
61
|
+
client: unknown;
|
|
62
|
+
project: unknown;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
host: string;
|
|
65
|
+
token: string;
|
|
66
|
+
}>;
|
|
67
|
+
claimHandoff(scope: import("../../core/review/model.ts").Scope, token: string): Promise<{
|
|
68
|
+
person: import("../../core/review/model.ts").Person;
|
|
69
|
+
project: string | null;
|
|
70
|
+
} | null>;
|
|
46
71
|
projectOf: ({ client, project }: import("../../core/review/model.ts").Scope) => Promise<import("../../core/review/model.ts").Project | null>;
|
|
47
72
|
listProjects(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Project[]>;
|
|
48
73
|
addClient(actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<import("../../core/review/model.ts").Client>;
|
|
@@ -68,22 +93,22 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
68
93
|
builds: import("../../core/review/service.ts").Build[];
|
|
69
94
|
}>;
|
|
70
95
|
forgetBuilds(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, builds: string[]): Promise<void>;
|
|
71
|
-
sessionPerson(
|
|
72
|
-
listPeople(
|
|
73
|
-
addPerson(
|
|
96
|
+
sessionPerson(at: import("../../core/review/service.ts").HostScope, id: string, epoch: number): Promise<import("../../core/review/model.ts").Person | null>;
|
|
97
|
+
listPeople(at: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Person[]>;
|
|
98
|
+
addPerson(at: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<{
|
|
74
99
|
person: import("../../core/review/model.ts").Person;
|
|
75
100
|
token: string;
|
|
76
101
|
}>;
|
|
77
|
-
newLink(scope: import("../../core/review/
|
|
102
|
+
newLink(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<{
|
|
78
103
|
person: import("../../core/review/model.ts").Person;
|
|
79
104
|
token: string;
|
|
80
105
|
}>;
|
|
81
|
-
signOutEverywhere(scope: import("../../core/review/
|
|
106
|
+
signOutEverywhere(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<{
|
|
82
107
|
person: import("../../core/review/model.ts").Person;
|
|
83
108
|
token: string;
|
|
84
109
|
}>;
|
|
85
|
-
revoke(scope: import("../../core/review/
|
|
86
|
-
setAccess(scope: import("../../core/review/
|
|
110
|
+
revoke(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<import("../../core/review/model.ts").Person>;
|
|
111
|
+
setAccess(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string, access: unknown): Promise<import("../../core/review/model.ts").Person>;
|
|
87
112
|
defaultAccess(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
|
|
88
113
|
setDefaultAccess(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, access: unknown): Promise<import("../../core/review/model.ts").Access>;
|
|
89
114
|
addStudioPerson(actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<import("../../core/review/model.ts").Person>;
|
|
@@ -93,8 +118,8 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
93
118
|
}>;
|
|
94
119
|
studioAccess(actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
|
|
95
120
|
setStudioAccess(actor: import("../../core/review/model.ts").Person | null, access: unknown): Promise<import("../../core/review/model.ts").Access>;
|
|
96
|
-
peekLink(
|
|
97
|
-
useLink(
|
|
121
|
+
peekLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
|
|
122
|
+
useLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
|
|
98
123
|
listComments(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, prototype: string, viewAs?: unknown): Promise<import("../../core/review/model.ts").Comment[]>;
|
|
99
124
|
allComments(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Comment[]>;
|
|
100
125
|
add(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, input: {
|
|
@@ -8,6 +8,7 @@ import { writeFileSync } from 'node:fs';
|
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { memoryFiles } from '../../core/files.js';
|
|
10
10
|
import { LINK_PATH, PROOF_PATH } from '../../core/prototype.js';
|
|
11
|
+
import { STUDIO_SITE } from '../../core/review/model.js';
|
|
11
12
|
import { createReview } from '../../core/review/service.js';
|
|
12
13
|
import { memoryKV } from '../../core/review/store.js';
|
|
13
14
|
import { hostCache } from '../../server/hosts.js';
|
|
@@ -131,7 +132,7 @@ export function fakeSite(review) {
|
|
|
131
132
|
const request = new Request(input, init);
|
|
132
133
|
const url = new URL(request.url);
|
|
133
134
|
const client = await hosts(url.hostname, (h) => review.clientOfHost(h));
|
|
134
|
-
if (!client)
|
|
135
|
+
if (!client || client === STUDIO_SITE)
|
|
135
136
|
return text(404, 'Not found.');
|
|
136
137
|
const scope = { client: client.slug };
|
|
137
138
|
const proof = url.pathname.match(PROOF_PATH);
|
|
@@ -161,10 +162,12 @@ export function fakeDeps(home, cwd = home) {
|
|
|
161
162
|
const clock = { at: Date.now() };
|
|
162
163
|
const review = createReview(kv, { now: () => new Date(clock.at) });
|
|
163
164
|
const files = memoryFiles();
|
|
164
|
-
// The gate's answer: the host's client, then the proof's answer in its scope.
|
|
165
|
+
// The gate's answer: the studio's own host's proof there, else the host's client, then the proof's answer in its scope.
|
|
165
166
|
fake.gate = async (host, ask) => {
|
|
166
|
-
const
|
|
167
|
-
|
|
167
|
+
const site = await review.siteOfHost(host);
|
|
168
|
+
if (site === STUDIO_SITE)
|
|
169
|
+
return review.studioProofAnswer(ask);
|
|
170
|
+
return site ? review.proofAnswer({ client: site.slug }, ask) : null;
|
|
168
171
|
};
|
|
169
172
|
const ensured = [];
|
|
170
173
|
const released = [];
|
|
@@ -26,7 +26,7 @@ export type StudioConfig = {
|
|
|
26
26
|
mode: DnsMode;
|
|
27
27
|
zone: string | null;
|
|
28
28
|
};
|
|
29
|
-
/** The first Studio person, who gets
|
|
29
|
+
/** The first Studio person, who gets the first link, on the studio's own host. */
|
|
30
30
|
owner: string | null;
|
|
31
31
|
providers: {
|
|
32
32
|
kv: 'upstash';
|
|
@@ -60,6 +60,8 @@ export type Studio = {
|
|
|
60
60
|
* never stands in for another studio.
|
|
61
61
|
*/
|
|
62
62
|
export declare function findStudio(home: string, named: string | undefined, cwd: string): Studio;
|
|
63
|
+
/** The studio's own host, where Studio signs in and sees every client: `studio.<apex>`. */
|
|
64
|
+
export declare const studioHost: (apex: string) => string;
|
|
63
65
|
/**
|
|
64
66
|
* The host a client is served on: `<slug>.<apex>`, or a codename
|
|
65
67
|
* (`--host atlas` is `atlas.<apex>`). A client's host is exactly one label
|
|
@@ -155,6 +155,8 @@ export function findStudio(home, named, cwd) {
|
|
|
155
155
|
});
|
|
156
156
|
return { dir: listed.dir, config };
|
|
157
157
|
}
|
|
158
|
+
/** The studio's own host, where Studio signs in and sees every client: `studio.<apex>`. */
|
|
159
|
+
export const studioHost = (apex) => `studio.${apex}`;
|
|
158
160
|
/** The first labels the studio keeps for itself, never a client's host. */
|
|
159
161
|
const KEPT_LABELS = ['studio', 'www', 'api'];
|
|
160
162
|
/** One DNS label: lower-case letters, digits and inner hyphens. */
|
package/dist/scripts/people.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const spec: {
|
|
|
6
6
|
readonly 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.';
|
|
7
7
|
readonly positionals: [{
|
|
8
8
|
readonly name: 'action';
|
|
9
|
-
readonly 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
|
|
9
|
+
readonly 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.';
|
|
10
10
|
}, {
|
|
11
11
|
readonly name: 'id';
|
|
12
12
|
readonly description: 'The person, for link, sign-out, revoke and access';
|
|
@@ -22,21 +22,24 @@ export declare const spec: {
|
|
|
22
22
|
};
|
|
23
23
|
readonly kind: {
|
|
24
24
|
readonly type: 'string';
|
|
25
|
-
readonly default: 'client';
|
|
26
25
|
readonly choices: readonly ["studio", "client"];
|
|
27
|
-
readonly description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and
|
|
26
|
+
readonly 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.';
|
|
28
27
|
};
|
|
29
28
|
readonly access: {
|
|
30
29
|
readonly type: 'string';
|
|
31
30
|
readonly choices: readonly ["3m", "6m", "open"];
|
|
32
31
|
readonly 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.';
|
|
33
32
|
};
|
|
33
|
+
readonly studio: {
|
|
34
|
+
readonly type: 'string';
|
|
35
|
+
readonly 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.';
|
|
36
|
+
};
|
|
34
37
|
readonly local: {
|
|
35
38
|
readonly type: 'boolean';
|
|
36
39
|
readonly description: 'Use this machine’s dev store, even in a project linked to a studio.';
|
|
37
40
|
};
|
|
38
41
|
};
|
|
39
|
-
readonly 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';
|
|
42
|
+
readonly 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.';
|
|
40
43
|
};
|
|
41
44
|
export declare function run({ positionals: [action, id], flags }: Args<typeof spec>, deps: ProjectDeps): Promise<Record<string, unknown>>;
|
|
42
45
|
export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
|