@milesroxas/design-hub 0.11.2 → 0.13.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 +8 -6
- 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 +262 -37
- package/core/review/service.ts +276 -52
- package/core/review/store.ts +12 -6
- package/core/review/suite-kv.ts +17 -0
- 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/core/review/store.js +2 -2
- package/dist/core/review/suite-kv.d.ts +7 -0
- package/dist/core/review/suite-kv.js +12 -0
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +55 -69
- package/dist/scripts/lib/cli.js +5 -0
- 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 +35 -11
- package/dist/scripts/lib/fake-host.js +27 -13
- package/dist/scripts/lib/host.d.ts +13 -25
- package/dist/scripts/lib/host.js +15 -324
- package/dist/scripts/lib/studio-deps.d.ts +16 -0
- package/dist/scripts/lib/studio-deps.js +41 -16
- package/dist/scripts/lib/studios.d.ts +17 -5
- package/dist/scripts/lib/studios.js +25 -5
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +410 -0
- package/dist/scripts/people.d.ts +7 -4
- package/dist/scripts/people.js +147 -39
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +10 -4
- package/dist/scripts/studio.js +136 -22
- package/dist/server/api.d.ts +12 -13
- package/dist/server/api.js +141 -52
- package/dist/server/gate.d.ts +97 -0
- package/dist/server/gate.js +537 -0
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +9 -1
- package/dist/server/session.js +10 -3
- package/dist/server/stores/backends.d.ts +22 -0
- package/dist/server/stores/backends.js +96 -0
- package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
- package/dist/server/stores/index.d.ts +41 -0
- package/dist/server/stores/index.js +63 -0
- package/dist/server/stores/pglite.d.ts +16 -0
- package/dist/server/stores/pglite.js +98 -0
- package/dist/server/stores/postgres.d.ts +63 -0
- package/dist/server/stores/postgres.js +153 -0
- package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
- package/dist/vercel/files.js +1 -1
- package/dist/vercel/proxy.d.ts +6 -78
- package/dist/vercel/proxy.js +18 -359
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +22 -4
- package/package.json +3 -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 +17 -6
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/.env.example +3 -0
- package/templates/studio/README.md +45 -13
- package/templates/studio/package.json +1 -1
- /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
- /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
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';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
30
|
+
import { pointHost, waitServed } from './lib/dns.js';
|
|
31
|
+
import { openFiles, openReview, realDeps, recordOf } from './lib/studio-deps.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;
|
|
@@ -203,7 +171,7 @@ async function add(ctx) {
|
|
|
203
171
|
// while this one waited on the host, and its projects' builds are live.
|
|
204
172
|
const current = await recordOf(review, slug);
|
|
205
173
|
if (current && !isAdded(current))
|
|
206
|
-
await clearPrefix(deps
|
|
174
|
+
await clearPrefix(await openFiles(deps, studio), clientPrefix(slug));
|
|
207
175
|
await prove(ctx, host, client, dns);
|
|
208
176
|
const at = (token) => `https://${client.host}/invite/${token}`;
|
|
209
177
|
try {
|
|
@@ -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
|
}
|
|
@@ -267,7 +234,7 @@ async function archive(ctx) {
|
|
|
267
234
|
// leaves the client readable; the record stays, archived, until they are done, so a run again
|
|
268
235
|
// still knows the host and each step finds what is left.
|
|
269
236
|
const archived = await review.archiveClient(scope, actor());
|
|
270
|
-
const files = await clearPrefix(deps
|
|
237
|
+
const files = await clearPrefix(await openFiles(deps, studio), clientPrefix(slug));
|
|
271
238
|
const record = archived?.client ?? null;
|
|
272
239
|
const wildcard = studio.config.dns.mode === 'wildcard';
|
|
273
240
|
// Another client's host, or one a live client's record names, is never taken off.
|
|
@@ -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
|
}
|
package/dist/scripts/lib/cli.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// schema, so an agent discovers the commands without reading their source.
|
|
7
7
|
import { parseArgs } from 'node:util';
|
|
8
8
|
import { MarkError } from '../../server/mark.js';
|
|
9
|
+
import { closeStores } from '../../server/stores/index.js';
|
|
9
10
|
/** A failure the caller can act on: the message, and the fix when there is one. */
|
|
10
11
|
export class CliError extends Error {
|
|
11
12
|
detail;
|
|
@@ -87,4 +88,8 @@ export async function runCommand(spec, main, argv = process.argv.slice(2)) {
|
|
|
87
88
|
print({ ok: false, error: error instanceof Error ? error.message : String(error), ...detail });
|
|
88
89
|
process.exitCode = 1;
|
|
89
90
|
}
|
|
91
|
+
finally {
|
|
92
|
+
// A Postgres store's idle connections would keep the process up after its one JSON object.
|
|
93
|
+
await closeStores();
|
|
94
|
+
}
|
|
90
95
|
}
|
|
@@ -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, }) {
|
|
@@ -21,8 +21,7 @@ export type FakeHost = {
|
|
|
21
21
|
export declare function fakeHost(older?: string[]): FakeHost;
|
|
22
22
|
/**
|
|
23
23
|
* The studio site as a fetch from outside meets it, over the commands' own
|
|
24
|
-
* store, answering as the gate does (
|
|
25
|
-
* keeps scripts from importing): a host no client has is the plain 404, the
|
|
24
|
+
* store, answering as the gate does (server/gate.ts), in short: a host no client has is the plain 404, the
|
|
26
25
|
* host proof's path answers the proof's answer for its ask, a link page is
|
|
27
26
|
* 200 while the link is live and a POST uses it up, anything else is the
|
|
28
27
|
* signed-out 401. It keeps each host's answer a minute, unknown hosts too,
|
|
@@ -43,6 +42,31 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
43
42
|
review: {
|
|
44
43
|
person: (scope: import("../../core/review/model.ts").Scope, id: string) => Promise<import("../../core/review/model.ts").Person | null>;
|
|
45
44
|
clientOfHost(host: string): Promise<import("../../core/review/model.ts").Client | null>;
|
|
45
|
+
siteOfHost: (host: string) => Promise<import("../../core/review/model.ts").Site>;
|
|
46
|
+
studioHostProven(actor: import("../../core/review/model.ts").Person | null): Promise<boolean>;
|
|
47
|
+
startStudioProof(actor: import("../../core/review/model.ts").Person | null): Promise<{
|
|
48
|
+
ask: string;
|
|
49
|
+
answer: string;
|
|
50
|
+
}>;
|
|
51
|
+
endStudioProof(actor: import("../../core/review/model.ts").Person | null): Promise<void>;
|
|
52
|
+
studioProofAnswer(ask: string): Promise<string | null>;
|
|
53
|
+
setStudioHost(actor: import("../../core/review/model.ts").Person | null, host: string): Promise<'added' | 'kept'>;
|
|
54
|
+
listClients(actor: import("../../core/review/model.ts").Person | null): Promise<{
|
|
55
|
+
client: import("../../core/review/model.ts").Client;
|
|
56
|
+
projects: import("../../core/review/model.ts").Project[];
|
|
57
|
+
}[]>;
|
|
58
|
+
studioClient(actor: import("../../core/review/model.ts").Person | null, slug: unknown): Promise<import("../../core/review/model.ts").Client>;
|
|
59
|
+
startHandoff(actor: import("../../core/review/model.ts").Person | null, input: {
|
|
60
|
+
client: unknown;
|
|
61
|
+
project: unknown;
|
|
62
|
+
}): Promise<{
|
|
63
|
+
host: string;
|
|
64
|
+
token: string;
|
|
65
|
+
}>;
|
|
66
|
+
claimHandoff(scope: import("../../core/review/model.ts").Scope, token: string): Promise<{
|
|
67
|
+
person: import("../../core/review/model.ts").Person;
|
|
68
|
+
project: string | null;
|
|
69
|
+
} | null>;
|
|
46
70
|
projectOf: ({ client, project }: import("../../core/review/model.ts").Scope) => Promise<import("../../core/review/model.ts").Project | null>;
|
|
47
71
|
listProjects(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Project[]>;
|
|
48
72
|
addClient(actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<import("../../core/review/model.ts").Client>;
|
|
@@ -68,22 +92,22 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
68
92
|
builds: import("../../core/review/service.ts").Build[];
|
|
69
93
|
}>;
|
|
70
94
|
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(
|
|
95
|
+
sessionPerson(at: import("../../core/review/service.ts").HostScope, id: string, epoch: number): Promise<import("../../core/review/model.ts").Person | null>;
|
|
96
|
+
listPeople(at: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Person[]>;
|
|
97
|
+
addPerson(at: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<{
|
|
74
98
|
person: import("../../core/review/model.ts").Person;
|
|
75
99
|
token: string;
|
|
76
100
|
}>;
|
|
77
|
-
newLink(scope: import("../../core/review/
|
|
101
|
+
newLink(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<{
|
|
78
102
|
person: import("../../core/review/model.ts").Person;
|
|
79
103
|
token: string;
|
|
80
104
|
}>;
|
|
81
|
-
signOutEverywhere(scope: import("../../core/review/
|
|
105
|
+
signOutEverywhere(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<{
|
|
82
106
|
person: import("../../core/review/model.ts").Person;
|
|
83
107
|
token: string;
|
|
84
108
|
}>;
|
|
85
|
-
revoke(scope: import("../../core/review/
|
|
86
|
-
setAccess(scope: import("../../core/review/
|
|
109
|
+
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>;
|
|
110
|
+
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
111
|
defaultAccess(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
|
|
88
112
|
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
113
|
addStudioPerson(actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<import("../../core/review/model.ts").Person>;
|
|
@@ -93,8 +117,8 @@ export declare function fakeDeps(home: string, cwd?: string): {
|
|
|
93
117
|
}>;
|
|
94
118
|
studioAccess(actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
|
|
95
119
|
setStudioAccess(actor: import("../../core/review/model.ts").Person | null, access: unknown): Promise<import("../../core/review/model.ts").Access>;
|
|
96
|
-
peekLink(
|
|
97
|
-
useLink(
|
|
120
|
+
peekLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
|
|
121
|
+
useLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
|
|
98
122
|
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
123
|
allComments(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Comment[]>;
|
|
100
124
|
add(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, input: {
|
|
@@ -8,10 +8,20 @@ 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';
|
|
14
15
|
import { manualDns, wildcardDns } from './dns.js';
|
|
16
|
+
import { hasStore, STORE_NAMES } from './studios.js';
|
|
17
|
+
/** What a new or connected database of each kind puts on the fake team's Production env. */
|
|
18
|
+
const DATABASES = {
|
|
19
|
+
upstash: { KV_REST_API_URL: 'https://kv.studio.test', KV_REST_API_TOKEN: 'kv-token-xxxxxxxx' },
|
|
20
|
+
postgres: {
|
|
21
|
+
DATABASE_URL: 'postgres://user:pg-secret-xxxxxxxx@db.studio.test/hub?sslmode=require',
|
|
22
|
+
POSTGRES_URL: 'postgres://user:pg-secret-xxxxxxxx@db.studio.test/hub?sslmode=require',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
15
25
|
export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
|
|
16
26
|
let next = 0;
|
|
17
27
|
const fake = {
|
|
@@ -54,17 +64,17 @@ export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
|
|
|
54
64
|
log(`pullEnv ${names.join(',')}`);
|
|
55
65
|
return Object.fromEntries(names.filter((n) => fake.env.has(n)).map((n) => [n, fake.env.get(n)]));
|
|
56
66
|
},
|
|
57
|
-
async provisionDatabase(existing) {
|
|
58
|
-
log(`provisionDatabase${existing ? ` ${existing}` : ''}`);
|
|
59
|
-
if (fake.env.has(
|
|
67
|
+
async provisionDatabase(kind, existing) {
|
|
68
|
+
log(`provisionDatabase${kind === 'upstash' ? '' : ` ${kind}`}${existing ? ` ${existing}` : ''}`);
|
|
69
|
+
if (hasStore(kind, (n) => fake.env.has(n)))
|
|
60
70
|
return 'kept';
|
|
61
|
-
store(
|
|
71
|
+
store(DATABASES[kind]);
|
|
62
72
|
return existing ? 'connected' : 'created';
|
|
63
73
|
},
|
|
64
|
-
async disconnectDatabase(name) {
|
|
74
|
+
async disconnectDatabase(kind, name) {
|
|
65
75
|
log(`disconnectDatabase ${name}`);
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
for (const n of STORE_NAMES[kind])
|
|
77
|
+
fake.env.delete(n);
|
|
68
78
|
return true;
|
|
69
79
|
},
|
|
70
80
|
async provisionFiles(region) {
|
|
@@ -118,8 +128,7 @@ export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
|
|
|
118
128
|
const text = (status, body) => new Response(body, { status, headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
119
129
|
/**
|
|
120
130
|
* The studio site as a fetch from outside meets it, over the commands' own
|
|
121
|
-
* store, answering as the gate does (
|
|
122
|
-
* keeps scripts from importing): a host no client has is the plain 404, the
|
|
131
|
+
* store, answering as the gate does (server/gate.ts), in short: a host no client has is the plain 404, the
|
|
123
132
|
* host proof's path answers the proof's answer for its ask, a link page is
|
|
124
133
|
* 200 while the link is live and a POST uses it up, anything else is the
|
|
125
134
|
* signed-out 401. It keeps each host's answer a minute, unknown hosts too,
|
|
@@ -131,7 +140,7 @@ export function fakeSite(review) {
|
|
|
131
140
|
const request = new Request(input, init);
|
|
132
141
|
const url = new URL(request.url);
|
|
133
142
|
const client = await hosts(url.hostname, (h) => review.clientOfHost(h));
|
|
134
|
-
if (!client)
|
|
143
|
+
if (!client || client === STUDIO_SITE)
|
|
135
144
|
return text(404, 'Not found.');
|
|
136
145
|
const scope = { client: client.slug };
|
|
137
146
|
const proof = url.pathname.match(PROOF_PATH);
|
|
@@ -161,10 +170,12 @@ export function fakeDeps(home, cwd = home) {
|
|
|
161
170
|
const clock = { at: Date.now() };
|
|
162
171
|
const review = createReview(kv, { now: () => new Date(clock.at) });
|
|
163
172
|
const files = memoryFiles();
|
|
164
|
-
// The gate's answer: the host's client, then the proof's answer in its scope.
|
|
173
|
+
// 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
174
|
fake.gate = async (host, ask) => {
|
|
166
|
-
const
|
|
167
|
-
|
|
175
|
+
const site = await review.siteOfHost(host);
|
|
176
|
+
if (site === STUDIO_SITE)
|
|
177
|
+
return review.studioProofAnswer(ask);
|
|
178
|
+
return site ? review.proofAnswer({ client: site.slug }, ask) : null;
|
|
168
179
|
};
|
|
169
180
|
const ensured = [];
|
|
170
181
|
const released = [];
|
|
@@ -224,6 +235,9 @@ export function fakeDeps(home, cwd = home) {
|
|
|
224
235
|
: perHost,
|
|
225
236
|
names,
|
|
226
237
|
store: () => kv,
|
|
238
|
+
prepareStore: async () => {
|
|
239
|
+
fake.calls.push('prepareStore');
|
|
240
|
+
},
|
|
227
241
|
now: () => new Date(clock.at),
|
|
228
242
|
files: () => files,
|
|
229
243
|
// Installs nothing: an install that passes writes the lockfile, as pnpm does.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StoreKind } from '../../server/stores/index.ts';
|
|
2
|
+
import type { StudioConfig } from './studios.ts';
|
|
2
3
|
export type Deployment = {
|
|
3
4
|
id: string;
|
|
4
5
|
state: string;
|
|
@@ -27,20 +28,20 @@ export interface Host {
|
|
|
27
28
|
/** Production values of these names, read into memory, never into a file left behind. */
|
|
28
29
|
pullEnv(names: readonly string[]): Promise<Record<string, string>>;
|
|
29
30
|
/**
|
|
30
|
-
* The review store (Upstash for Redis) when
|
|
31
|
-
* team's existing database of the name given,
|
|
32
|
-
* one, only ever on the free plan. A database
|
|
33
|
-
* `studio create` checks the one connected is no
|
|
34
|
-
* writes to it (server/mark.ts).
|
|
31
|
+
* The review store of this kind (Upstash for Redis, or Postgres) when
|
|
32
|
+
* production has none: the team's existing database of the name given,
|
|
33
|
+
* connected, or else a new one, only ever on the free plan. A database
|
|
34
|
+
* serves one studio only: `studio create` checks the one connected is no
|
|
35
|
+
* other studio's before it writes to it (server/mark.ts).
|
|
35
36
|
*/
|
|
36
|
-
provisionDatabase(existing?: string): Promise<'created' | 'connected' | 'kept'>;
|
|
37
|
+
provisionDatabase(kind: StoreKind, existing?: string): Promise<'created' | 'connected' | 'kept'>;
|
|
37
38
|
/**
|
|
38
39
|
* Takes the team's database of this name off the studio project, its
|
|
39
40
|
* env vars with it, for a `studio create` that connected another studio's.
|
|
40
|
-
* True once Production holds
|
|
41
|
-
* disconnect failed or left them, so the refusal can say what is left.
|
|
41
|
+
* True once Production holds none of the kind's store names; false when
|
|
42
|
+
* the disconnect failed or left them, so the refusal can say what is left.
|
|
42
43
|
*/
|
|
43
|
-
disconnectDatabase(name: string): Promise<boolean>;
|
|
44
|
+
disconnectDatabase(kind: StoreKind, name: string): Promise<boolean>;
|
|
44
45
|
/** The private file store (Vercel Blob), made and connected when production has none. */
|
|
45
46
|
provisionFiles(region: string): Promise<'created' | 'kept'>;
|
|
46
47
|
/** Puts a host on the studio project, or asks Vercel to verify one already there. */
|
|
@@ -70,18 +71,5 @@ export declare function deployAlone(host: Host): Promise<{
|
|
|
70
71
|
deployment: string;
|
|
71
72
|
removed: string[];
|
|
72
73
|
}>;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
team: string;
|
|
76
|
-
project: string;
|
|
77
|
-
run?: (cwd: string, args: string[], input?: string) => Run | null;
|
|
78
|
-
fetcher?: typeof fetch;
|
|
79
|
-
wait?: (ms: number) => Promise<unknown>;
|
|
80
|
-
};
|
|
81
|
-
/** The env vars the Vercel CLI (59.x) reads to pick a project or team over the folder's link and `--scope`. */
|
|
82
|
-
export declare const PICKERS: string[];
|
|
83
|
-
/** The Vercel adapter. Every call goes through `call`, which adds `--scope <team>`. */
|
|
84
|
-
export declare function vercelHost({ dir, team, project, run, fetcher, wait, }: VercelOptions): Host;
|
|
85
|
-
/** Vercel's first-ranked CNAME for a host, without its trailing dot. */
|
|
86
|
-
export declare function cnameTarget(config: Record<string, any> | null): string;
|
|
87
|
-
export {};
|
|
74
|
+
/** The host adapter a studio names, or a refusal that names the ones there are. */
|
|
75
|
+
export declare function hostFor(dir: string, config: StudioConfig, hosts?: Record<string, (dir: string, config: StudioConfig) => Host>): Host;
|