@milesroxas/design-hub 0.6.2 → 0.8.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 +16 -6
- package/core/review/model.ts +124 -6
- package/core/review/policy.test.ts +103 -24
- package/core/review/policy.ts +43 -7
- package/core/review/service.test.ts +569 -33
- package/core/review/service.ts +272 -76
- package/core/review/store.ts +24 -4
- package/dist/core/review/model.d.ts +59 -4
- package/dist/core/review/model.js +98 -4
- package/dist/core/review/policy.d.ts +21 -2
- package/dist/core/review/policy.js +34 -2
- package/dist/core/review/service.d.ts +39 -11
- package/dist/core/review/service.js +237 -77
- package/dist/core/review/store.d.ts +17 -4
- package/dist/core/review/store.js +21 -3
- package/dist/scripts/bootstrap.d.ts +16 -14
- package/dist/scripts/bootstrap.js +56 -39
- package/dist/scripts/comments.d.ts +10 -2
- package/dist/scripts/comments.js +18 -7
- package/dist/scripts/lib/deploy.d.ts +12 -4
- package/dist/scripts/lib/deploy.js +47 -13
- package/dist/scripts/lib/vercel.d.ts +8 -2
- package/dist/scripts/lib/vercel.js +23 -9
- package/dist/scripts/people.d.ts +13 -26
- package/dist/scripts/people.js +68 -35
- package/dist/scripts/preflight.js +2 -2
- package/dist/scripts/share.d.ts +2 -3
- package/dist/scripts/share.js +18 -10
- package/dist/server/api.d.ts +6 -2
- package/dist/server/api.js +65 -24
- package/dist/server/fake-upstash.js +3 -2
- package/dist/server/local.js +2 -0
- package/dist/server/session.d.ts +25 -10
- package/dist/server/session.js +69 -52
- package/dist/server/upstash.js +4 -3
- package/dist/vercel/proxy.d.ts +5 -3
- package/dist/vercel/proxy.js +183 -157
- package/dist/vite/plugin.js +5 -5
- package/kit/prefs.ts +19 -2
- package/package.json +2 -2
- package/shell/review/Bar.tsx +97 -4
- package/shell/review/People.tsx +178 -45
- package/shell/review/Pins.tsx +39 -24
- package/shell/review/Review.tsx +113 -29
- package/shell/review/ThreadCard.tsx +25 -13
- package/shell/review/client.ts +64 -23
- package/shell/review/review.css +16 -2
- package/shell/review/view.test.ts +73 -1
- package/shell/review/view.ts +49 -3
- package/skills/miles-deploy/SKILL.md +44 -16
- package/skills/miles-design-hub/SKILL.md +5 -5
- package/skills/miles-new-feature/SKILL.md +1 -1
- package/skills/miles-review/SKILL.md +10 -6
- package/skills/miles-worktrees/SKILL.md +1 -1
- package/templates/conductor/settings.toml +1 -1
- package/templates/guide.md +1 -1
|
@@ -8,11 +8,13 @@ import { randomBytes } from 'node:crypto';
|
|
|
8
8
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
9
|
import { tmpdir } from 'node:os';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
+
import { ACCESS } from '../core/review/model.js';
|
|
11
12
|
import { harnessPort, readEnv, writeEnv } from '../server/env.js';
|
|
12
13
|
import { ROOT, TEMPLATES } from '../server/paths.js';
|
|
13
14
|
import { CliError } from './lib/cli.js';
|
|
14
15
|
import { gitConnected, restoreGitignore, upstashTerms } from './lib/deploy.js';
|
|
15
16
|
import { holderOf, pickPort, readClaims, writeClaim } from './lib/ports.js';
|
|
17
|
+
import { cliActor, cliReview } from './lib/review.js';
|
|
16
18
|
import { ENVIRONMENTS, envNames, linkedOrg, linkedProject, projectInfo, STORE_ENV, setEnv, vercel, whoami, } from './lib/vercel.js';
|
|
17
19
|
export const spec = {
|
|
18
20
|
name: 'bootstrap',
|
|
@@ -26,21 +28,25 @@ export const spec = {
|
|
|
26
28
|
'typesafe-key': { type: 'string', description: "Turn TypeSafe's Jev checks on with this API key." },
|
|
27
29
|
conductor: { type: 'boolean', description: 'Write .conductor/settings.toml for Conductor workspaces.' },
|
|
28
30
|
branch: { type: 'string', default: 'main', description: 'The branch Conductor workspaces land on.' },
|
|
29
|
-
vercel: {
|
|
30
|
-
team: {
|
|
31
|
+
vercel: {
|
|
31
32
|
type: 'string',
|
|
32
|
-
description: '
|
|
33
|
+
description: 'Link this Vercel project and set the gate’s signing secret on it.',
|
|
33
34
|
},
|
|
34
|
-
|
|
35
|
+
team: {
|
|
35
36
|
type: 'string',
|
|
36
|
-
description: 'The
|
|
37
|
+
description: 'The Vercel team (its slug) the project lives in or is created in. Absent, the CLI’s current team.',
|
|
37
38
|
},
|
|
38
39
|
review: {
|
|
39
40
|
type: 'boolean',
|
|
40
41
|
description: 'Provision the review store (Upstash Redis) on the Vercel project.',
|
|
41
42
|
},
|
|
43
|
+
access: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
choices: ACCESS,
|
|
46
|
+
description: 'With --review: how long a new client keeps access by default, 3m, 6m or open. Absent, the store keeps what it has (3m when unset).',
|
|
47
|
+
},
|
|
42
48
|
},
|
|
43
|
-
output: '{ ok, node, port, install, typesafe, conductor?, vercel: { project, linked, git, protection, env }?,
|
|
49
|
+
output: '{ ok, node, port, install, typesafe, conductor?, vercel: { project, linked, git, protection, env }?, review: { store, local, access? }?, warnings }',
|
|
44
50
|
};
|
|
45
51
|
const MIN_NODE = [22, 18];
|
|
46
52
|
const UPSTASH = 'upstash/upstash-kv';
|
|
@@ -186,12 +192,12 @@ function link(project, team, warnings) {
|
|
|
186
192
|
* when a step throws: `vercel link` appends to it, and a later failure (the
|
|
187
193
|
* Upstash terms, most often) would otherwise leave the tree dirty.
|
|
188
194
|
*/
|
|
189
|
-
export function keepingGitignore(dir, steps) {
|
|
195
|
+
export async function keepingGitignore(dir, steps) {
|
|
190
196
|
const file = join(dir, '.gitignore');
|
|
191
197
|
const read = () => (existsSync(file) ? readFileSync(file, 'utf8') : '');
|
|
192
198
|
const before = read();
|
|
193
199
|
try {
|
|
194
|
-
return steps();
|
|
200
|
+
return await steps();
|
|
195
201
|
}
|
|
196
202
|
finally {
|
|
197
203
|
const kept = restoreGitignore(before, read());
|
|
@@ -223,8 +229,8 @@ function connectGit(project, team, warnings) {
|
|
|
223
229
|
(out?.stderr.trim().split('\n').pop() ?? ''));
|
|
224
230
|
return 'none';
|
|
225
231
|
}
|
|
226
|
-
/** Sets each value where it is missing
|
|
227
|
-
function ensureEnv(values
|
|
232
|
+
/** Sets each value where it is missing, and keeps the ones already there. */
|
|
233
|
+
function ensureEnv(values) {
|
|
228
234
|
const state = {};
|
|
229
235
|
for (const target of ENVIRONMENTS) {
|
|
230
236
|
const names = envNames(ROOT, target);
|
|
@@ -234,24 +240,18 @@ function ensureEnv(values, rotate) {
|
|
|
234
240
|
});
|
|
235
241
|
for (const [name, value] of Object.entries(values)) {
|
|
236
242
|
const key = `${name}:${target}`;
|
|
237
|
-
|
|
238
|
-
if (exists && !rotate.has(name)) {
|
|
243
|
+
if (names.has(name)) {
|
|
239
244
|
state[key] = 'kept';
|
|
240
245
|
continue;
|
|
241
246
|
}
|
|
242
|
-
const out = setEnv(ROOT, name, target, value
|
|
247
|
+
const out = setEnv(ROOT, name, target, value);
|
|
243
248
|
if (out?.status !== 0)
|
|
244
249
|
throw new CliError(`vercel env add ${name} ${target} failed.`, { stderr: out?.stderr.trim() });
|
|
245
|
-
state[key] =
|
|
250
|
+
state[key] = 'set';
|
|
246
251
|
}
|
|
247
252
|
}
|
|
248
253
|
return state;
|
|
249
254
|
}
|
|
250
|
-
// A password a reviewer can type from a message: lowercase letters and digits, no look-alikes.
|
|
251
|
-
function readablePassword() {
|
|
252
|
-
const alphabet = 'abcdefghjkmnpqrstuvwxyz23456789';
|
|
253
|
-
return Array.from(randomBytes(12), (b) => alphabet[b % alphabet.length]).join('');
|
|
254
|
-
}
|
|
255
255
|
/** Reads one environment's values into memory and deletes the file, keeping only `names`. */
|
|
256
256
|
function pullValues(target, names) {
|
|
257
257
|
const dir = mkdtempSync(join(tmpdir(), 'hub-env-'));
|
|
@@ -332,42 +332,55 @@ function typesafe(given, current) {
|
|
|
332
332
|
writeEnv(ROOT, { TYPESAFE_API_KEY: given });
|
|
333
333
|
return given;
|
|
334
334
|
}
|
|
335
|
-
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
335
|
+
/**
|
|
336
|
+
* The gate's env: the signing secret, kept when .env has one and made once
|
|
337
|
+
* otherwise. Nothing else: people sign in with their own one-time links.
|
|
338
|
+
*/
|
|
339
|
+
export function gateValues(env) {
|
|
340
|
+
return { GATE_SECRET: env.GATE_SECRET || randomBytes(32).toString('base64') };
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Sets the project default access length in the deployed store. When the
|
|
344
|
+
* store's credentials did not reach .env, the CLI would reach the local
|
|
345
|
+
* store instead, so it says how to set it later rather than set the wrong one.
|
|
346
|
+
*/
|
|
347
|
+
async function setDefaultAccess(access, warnings) {
|
|
348
|
+
const { review, store } = cliReview(false);
|
|
349
|
+
if (store !== 'deployed') {
|
|
350
|
+
warnings.push(`Could not set the default access length: the store's credentials are not in .env. Once they are, run design-hub people access --access ${access}.`);
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
return review.setDefaultAccess(cliActor(), access);
|
|
342
354
|
}
|
|
343
|
-
function setUpVercel(project, flags, env, typesafeKey, warnings) {
|
|
355
|
+
async function setUpVercel(project, flags, env, typesafeKey, warnings) {
|
|
344
356
|
if (!whoami(ROOT))
|
|
345
357
|
throw new CliError('The Vercel CLI is not installed or not signed in.', {
|
|
346
358
|
fix: 'design-hub signin, send the user its url, then run this again.',
|
|
347
359
|
});
|
|
348
360
|
const linked = link(project, flags.team, warnings);
|
|
349
|
-
const
|
|
350
|
-
writeEnv(ROOT,
|
|
351
|
-
const values = {
|
|
361
|
+
const gate = gateValues(env);
|
|
362
|
+
writeEnv(ROOT, gate);
|
|
363
|
+
const values = { ...gate };
|
|
352
364
|
// Comment triage runs on the server, so with the review store on, the key goes to Vercel too.
|
|
353
365
|
if (flags.review && typesafeKey)
|
|
354
366
|
values.TYPESAFE_API_KEY = typesafeKey;
|
|
355
|
-
if (rotated)
|
|
356
|
-
warnings.push('The password changed: every visitor signs in again.');
|
|
357
367
|
const result = {
|
|
358
368
|
vercel: {
|
|
359
369
|
project,
|
|
360
370
|
linked,
|
|
361
371
|
git: connectGit(project, flags.team, warnings),
|
|
362
372
|
protection: protection(project, flags.team),
|
|
363
|
-
env: ensureEnv(values
|
|
373
|
+
env: ensureEnv(values),
|
|
364
374
|
},
|
|
365
|
-
share: { password },
|
|
366
375
|
};
|
|
367
|
-
if (!flags.review)
|
|
376
|
+
if (!flags.review) {
|
|
377
|
+
warnings.push('Nobody can sign in yet: each person signs in with a one-time link the review store keeps. Run this again with --review.');
|
|
368
378
|
return result;
|
|
369
|
-
|
|
370
|
-
|
|
379
|
+
}
|
|
380
|
+
const review = provisionReview(project, flags.team, warnings);
|
|
381
|
+
const access = flags.access ? await setDefaultAccess(flags.access, warnings) : undefined;
|
|
382
|
+
warnings.push('Run design-hub share so the new env reaches the site; then design-hub people add --name "<you>" --team "<studio>" --kind studio --site <url>.');
|
|
383
|
+
return { ...result, review: access ? { ...review, access } : review };
|
|
371
384
|
}
|
|
372
385
|
function envIgnored(warnings) {
|
|
373
386
|
try {
|
|
@@ -383,9 +396,13 @@ function envIgnored(warnings) {
|
|
|
383
396
|
if (tracked.status === 0)
|
|
384
397
|
warnings.push('.claude/launch.json is committed but holds this folder’s port. Run `git rm --cached .claude/launch.json` and add it to .gitignore.');
|
|
385
398
|
}
|
|
386
|
-
export function main({ flags }) {
|
|
399
|
+
export async function main({ flags }) {
|
|
387
400
|
if (flags.review && !flags.vercel)
|
|
388
401
|
throw new CliError('--review needs --vercel <project>.');
|
|
402
|
+
if (flags.access && !flags.review)
|
|
403
|
+
throw new CliError('--access needs --review.', {
|
|
404
|
+
fix: 'Or set it later: design-hub people access --access <3m|6m|open>.',
|
|
405
|
+
});
|
|
389
406
|
const warnings = [];
|
|
390
407
|
const node = checkNode();
|
|
391
408
|
const env = readEnv(ROOT);
|
|
@@ -402,7 +419,7 @@ export function main({ flags }) {
|
|
|
402
419
|
result.conductor = writeConductor(flags.branch, warnings);
|
|
403
420
|
const project = flags.vercel;
|
|
404
421
|
if (project)
|
|
405
|
-
Object.assign(result, keepingGitignore(ROOT, () => setUpVercel(project, flags, env, typesafeKey, warnings)));
|
|
422
|
+
Object.assign(result, await keepingGitignore(ROOT, () => setUpVercel(project, flags, env, typesafeKey, warnings)));
|
|
406
423
|
envIgnored(warnings);
|
|
407
424
|
return { ...result, warnings };
|
|
408
425
|
}
|
|
@@ -8,7 +8,7 @@ export declare const spec: {
|
|
|
8
8
|
readonly summary: 'Read review comments into the repo, resolve them, or sort the unsorted ones.';
|
|
9
9
|
readonly positionals: [{
|
|
10
10
|
readonly name: 'action';
|
|
11
|
-
readonly description: 'summary (default): open and
|
|
11
|
+
readonly description: 'summary (default): open, resolved, internal and client-facing counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind, each thread with its number and audience. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.';
|
|
12
12
|
}, {
|
|
13
13
|
readonly name: 'id';
|
|
14
14
|
readonly description: 'The comment, for resolve and reopen';
|
|
@@ -25,7 +25,10 @@ export declare const spec: {
|
|
|
25
25
|
};
|
|
26
26
|
readonly output: '{ ok, store, ... } per action';
|
|
27
27
|
};
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* One feature's comments as Markdown: by README state in table order, then
|
|
30
|
+
* kind; each thread with its number and audience, replies under it.
|
|
31
|
+
*/
|
|
29
32
|
export declare function renderComments(feature: string, comments: Comment[], stateOrder: string[]): string;
|
|
30
33
|
type Context = {
|
|
31
34
|
review: Review;
|
|
@@ -33,11 +36,14 @@ type Context = {
|
|
|
33
36
|
all: Comment[];
|
|
34
37
|
roots: Comment[];
|
|
35
38
|
};
|
|
39
|
+
/** Threads per prototype: open and resolved, and internal and client-facing. */
|
|
36
40
|
export declare function summary({ store, roots }: Pick<Context, 'store' | 'roots'>): {
|
|
37
41
|
store: "deployed" | "local";
|
|
38
42
|
prototypes: Record<string, {
|
|
39
43
|
open: number;
|
|
40
44
|
resolved: number;
|
|
45
|
+
internal: number;
|
|
46
|
+
client: number;
|
|
41
47
|
}>;
|
|
42
48
|
};
|
|
43
49
|
export declare function main({ positionals: [action, id], flags }: Args<typeof spec>): Promise<{
|
|
@@ -45,6 +51,8 @@ export declare function main({ positionals: [action, id], flags }: Args<typeof s
|
|
|
45
51
|
prototypes: Record<string, {
|
|
46
52
|
open: number;
|
|
47
53
|
resolved: number;
|
|
54
|
+
internal: number;
|
|
55
|
+
client: number;
|
|
48
56
|
}>;
|
|
49
57
|
} | {
|
|
50
58
|
store: "deployed" | "local";
|
package/dist/scripts/comments.js
CHANGED
|
@@ -20,7 +20,7 @@ export const spec = {
|
|
|
20
20
|
positionals: [
|
|
21
21
|
{
|
|
22
22
|
name: 'action',
|
|
23
|
-
description: 'summary (default): open and
|
|
23
|
+
description: 'summary (default): open, resolved, internal and client-facing counts per prototype. pull: docs/sprints/<feature>/comments.md, by state then kind, each thread with its number and audience. resolve or reopen <id>. triage: sort what Jev left unsorted, against the README states on disk.',
|
|
24
24
|
},
|
|
25
25
|
{ name: 'id', description: 'The comment, for resolve and reopen' },
|
|
26
26
|
],
|
|
@@ -35,6 +35,7 @@ export const spec = {
|
|
|
35
35
|
};
|
|
36
36
|
const NO_STATE = 'No state';
|
|
37
37
|
const KIND_TITLE = { bug: 'Bugs', taste: 'Taste', copy: 'Copy' };
|
|
38
|
+
const AUDIENCE_WORD = { internal: 'internal', client: 'client-facing' };
|
|
38
39
|
const stateOf = (c) => c.triage?.state ?? NO_STATE;
|
|
39
40
|
const isRoot = (c) => c.thread === c.id;
|
|
40
41
|
// A body without closing punctuation gets a full stop, so the location after it reads apart from it.
|
|
@@ -46,7 +47,12 @@ function threadLines(root, comments) {
|
|
|
46
47
|
: '';
|
|
47
48
|
const resolved = root.status === 'resolved' ? ' Resolved.' : '';
|
|
48
49
|
const replies = comments.filter((c) => c.thread === root.id && !isRoot(c));
|
|
49
|
-
|
|
50
|
+
// The number the panel shows (none on a thread stored before numbers), then who the thread is for.
|
|
51
|
+
const head = `${root.number ? `#${root.number} ` : ''}(${AUDIENCE_WORD[root.audience]})`;
|
|
52
|
+
return [
|
|
53
|
+
`- ${head} ${line(root)}${where}${resolved} id \`${root.id}\``,
|
|
54
|
+
...replies.map((r) => ` - ${line(r)}`),
|
|
55
|
+
];
|
|
50
56
|
}
|
|
51
57
|
function stateSection(state, roots, comments) {
|
|
52
58
|
const out = ['', `## ${state}`];
|
|
@@ -57,24 +63,29 @@ function stateSection(state, roots, comments) {
|
|
|
57
63
|
}
|
|
58
64
|
return out;
|
|
59
65
|
}
|
|
60
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* One feature's comments as Markdown: by README state in table order, then
|
|
68
|
+
* kind; each thread with its number and audience, replies under it.
|
|
69
|
+
*/
|
|
61
70
|
export function renderComments(feature, comments, stateOrder) {
|
|
62
71
|
const roots = comments.filter(isRoot);
|
|
63
72
|
const states = [...new Set([...stateOrder, ...roots.map(stateOf)])].filter((s) => roots.some((c) => stateOf(c) === s));
|
|
64
73
|
const out = [
|
|
65
74
|
`# Comments: ${featureTitle(feature)}`,
|
|
66
75
|
'',
|
|
67
|
-
'Generated by `pnpm comments pull`; a second pull replaces it. Resolve a comment in the review panel or with `pnpm comments resolve <id>`, never here.',
|
|
76
|
+
'Generated by `pnpm comments pull`; a second pull replaces it. Resolve a comment in the review panel or with `pnpm comments resolve <id>`, never here. An internal thread is seen by Studio only; a client-facing one by everyone.',
|
|
68
77
|
...states.flatMap((state) => stateSection(state, roots, comments)),
|
|
69
78
|
];
|
|
70
79
|
return `${out.join('\n')}\n`;
|
|
71
80
|
}
|
|
81
|
+
/** Threads per prototype: open and resolved, and internal and client-facing. */
|
|
72
82
|
export function summary({ store, roots }) {
|
|
73
83
|
const by = {};
|
|
74
84
|
for (const c of roots) {
|
|
75
85
|
const key = c.anchor?.prototype ?? 'unknown';
|
|
76
|
-
by[key] ??= { open: 0, resolved: 0 };
|
|
86
|
+
by[key] ??= { open: 0, resolved: 0, internal: 0, client: 0 };
|
|
77
87
|
by[key][c.status]++;
|
|
88
|
+
by[key][c.audience]++;
|
|
78
89
|
}
|
|
79
90
|
return { store, prototypes: by };
|
|
80
91
|
}
|
|
@@ -106,7 +117,7 @@ async function setStatus({ review, store }, id, resolved) {
|
|
|
106
117
|
throw new CliError(`Name the comment: pnpm comments ${action} <id>.`, {
|
|
107
118
|
fix: 'pnpm comments pull lists ids.',
|
|
108
119
|
});
|
|
109
|
-
const found = await review.locate(id);
|
|
120
|
+
const found = await review.locate(cliActor(), id);
|
|
110
121
|
if (!found)
|
|
111
122
|
throw new CliError('No comment has that id.', { id });
|
|
112
123
|
const comment = await review.resolve(cliActor(), { prototype: found.prototype, id, resolved });
|
|
@@ -134,7 +145,7 @@ async function triage({ review, store, roots }) {
|
|
|
134
145
|
}
|
|
135
146
|
export async function main({ positionals: [action = 'summary', id], flags }) {
|
|
136
147
|
const { review, store } = cliReview(flags.local);
|
|
137
|
-
const all = await review.allComments();
|
|
148
|
+
const all = await review.allComments(cliActor());
|
|
138
149
|
const ctx = { review, store, all, roots: all.filter(isRoot) };
|
|
139
150
|
switch (action) {
|
|
140
151
|
case 'summary':
|
|
@@ -45,9 +45,9 @@ export type Plan = {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function plan(repo: Repo, forceCli: boolean): Plan;
|
|
47
47
|
/**
|
|
48
|
-
* How `design-hub share` asks for the home page: as a browser does
|
|
49
|
-
* answers a client that does not accept HTML with a plain-text
|
|
50
|
-
* no
|
|
48
|
+
* How `design-hub share` asks for the home page: as a browser does, signed
|
|
49
|
+
* out. The gate answers a client that does not accept HTML with a plain-text
|
|
50
|
+
* 401, which has no sign-in page to find.
|
|
51
51
|
*/
|
|
52
52
|
export declare const GATE_REQUEST: {
|
|
53
53
|
readonly redirect: 'manual';
|
|
@@ -68,8 +68,16 @@ export type Verdict = {
|
|
|
68
68
|
problem: string;
|
|
69
69
|
fix: string;
|
|
70
70
|
};
|
|
71
|
-
/** Whether the production URL answers a signed-out visitor with the hub's
|
|
71
|
+
/** Whether the production URL answers a signed-out visitor with the hub's sign-in page. */
|
|
72
72
|
export declare function gateVerdict(answer: Answer): Verdict;
|
|
73
|
+
/**
|
|
74
|
+
* A link no store holds, asked for as a browser does once the sign-in page
|
|
75
|
+
* passed: it proves the review store is wired, since people sign in only with
|
|
76
|
+
* links it keeps. 43 characters, the length of a real token.
|
|
77
|
+
*/
|
|
78
|
+
export declare const PROBE_LINK: string;
|
|
79
|
+
/** Whether the probe link's answer shows a review store behind the gate: 404 means it looked and found nothing. */
|
|
80
|
+
export declare function storeVerdict(status: number): Verdict;
|
|
73
81
|
export type Seen = {
|
|
74
82
|
url: string;
|
|
75
83
|
state: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// What `design-hub signin` and `design-hub share` decide, kept apart from the
|
|
3
3
|
// vercel and git calls that feed them so every branch is tested: the sign-in
|
|
4
4
|
// link in the CLI's log, which way a deploy goes, the production URL, and
|
|
5
|
-
// whether the deployed site answers with the gate.
|
|
5
|
+
// whether the deployed site answers with the gate's sign-in page.
|
|
6
6
|
/** The device sign-in `vercel login` prints and then waits on. */
|
|
7
7
|
export function deviceLink(log) {
|
|
8
8
|
const m = log.match(/https:\/\/vercel\.com\/oauth\/device\?user_code=([A-Z0-9-]+)/);
|
|
@@ -39,38 +39,54 @@ export function plan(repo, forceCli) {
|
|
|
39
39
|
return { via: 'git', branch: repo.productionBranch };
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* How `design-hub share` asks for the home page: as a browser does
|
|
43
|
-
* answers a client that does not accept HTML with a plain-text
|
|
44
|
-
* no
|
|
42
|
+
* How `design-hub share` asks for the home page: as a browser does, signed
|
|
43
|
+
* out. The gate answers a client that does not accept HTML with a plain-text
|
|
44
|
+
* 401, which has no sign-in page to find.
|
|
45
45
|
*/
|
|
46
46
|
export const GATE_REQUEST = {
|
|
47
47
|
redirect: 'manual',
|
|
48
48
|
headers: { accept: 'text/html,application/xhtml+xml' },
|
|
49
49
|
};
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/** The hub's sign-in page carries this on its main element (vercel/proxy.ts). */
|
|
51
|
+
const SIGN_IN_MARKER = 'data-gate="sign-in"';
|
|
52
|
+
const quote = (body) => JSON.stringify(body.replace(/\s+/g, ' ').trim().slice(0, 80));
|
|
53
|
+
/** The first problem with the status alone, or null when it is the 401 the gate answers. */
|
|
54
|
+
function statusProblem(answer) {
|
|
52
55
|
if (answer.status >= 300 && answer.status < 400 && /vercel\.com/.test(answer.location ?? ''))
|
|
53
56
|
return {
|
|
54
57
|
ok: false,
|
|
55
|
-
problem: 'Visitors are sent to a Vercel login before the
|
|
56
|
-
fix: 'design-hub bootstrap --vercel <project> turns Vercel Authentication off; run it, then deploy again.',
|
|
58
|
+
problem: 'Visitors are sent to a Vercel login before the sign-in page.',
|
|
59
|
+
fix: 'design-hub bootstrap --vercel <project> --review turns Vercel Authentication off; run it, then deploy again.',
|
|
57
60
|
};
|
|
58
61
|
if (answer.status === 503)
|
|
59
62
|
return {
|
|
60
63
|
ok: false,
|
|
61
|
-
problem: 'The gate answers 503:
|
|
62
|
-
fix: 'design-hub bootstrap --vercel <project
|
|
64
|
+
problem: 'The gate answers 503: GATE_SECRET is missing on the deployment.',
|
|
65
|
+
fix: 'design-hub bootstrap --vercel <project> --review, then deploy again so the env reaches the site.',
|
|
63
66
|
};
|
|
64
67
|
if (answer.status !== 401)
|
|
65
68
|
return {
|
|
66
69
|
ok: false,
|
|
67
|
-
problem: `Expected the
|
|
70
|
+
problem: `Expected the sign-in page (401), got ${answer.status}.`,
|
|
68
71
|
fix: 'Check that proxy.ts and vercel.json are the template’s, then deploy again.',
|
|
69
72
|
};
|
|
70
|
-
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
/** Whether the production URL answers a signed-out visitor with the hub's sign-in page. */
|
|
76
|
+
export function gateVerdict(answer) {
|
|
77
|
+
const status = statusProblem(answer);
|
|
78
|
+
if (status)
|
|
79
|
+
return status;
|
|
80
|
+
if (/name="password"/.test(answer.body))
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
problem: 'The site still asks for a password: it runs a hub from before one-time links.',
|
|
84
|
+
fix: 'Commit the updated @milesroxas/design-hub (package.json and pnpm-lock.yaml), then deploy again.',
|
|
85
|
+
};
|
|
86
|
+
if (!answer.body.includes(SIGN_IN_MARKER))
|
|
71
87
|
return {
|
|
72
88
|
ok: false,
|
|
73
|
-
problem: `The site answered 401, but the body was not the
|
|
89
|
+
problem: `The site answered 401, but the body was not the sign-in page: ${quote(answer.body)}.`,
|
|
74
90
|
fix: 'Something other than the hub’s gate answered. Check that Vercel’s Password Protection is off and that proxy.ts and vercel.json are the template’s, then deploy again.',
|
|
75
91
|
};
|
|
76
92
|
if (!/noindex/.test(answer.robots ?? ''))
|
|
@@ -81,6 +97,24 @@ export function gateVerdict(answer) {
|
|
|
81
97
|
};
|
|
82
98
|
return { ok: true };
|
|
83
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* A link no store holds, asked for as a browser does once the sign-in page
|
|
102
|
+
* passed: it proves the review store is wired, since people sign in only with
|
|
103
|
+
* links it keeps. 43 characters, the length of a real token.
|
|
104
|
+
*/
|
|
105
|
+
export const PROBE_LINK = `/invite/${'x'.repeat(43)}`;
|
|
106
|
+
/** Whether the probe link's answer shows a review store behind the gate: 404 means it looked and found nothing. */
|
|
107
|
+
export function storeVerdict(status) {
|
|
108
|
+
if (status === 404)
|
|
109
|
+
return { ok: true };
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
problem: status === 503
|
|
113
|
+
? 'The site has no review store, so nobody can sign in: people sign in with links it keeps.'
|
|
114
|
+
: `A sign-in link answered ${status}, not 404, so the review store could not be checked.`,
|
|
115
|
+
fix: 'pnpm bootstrap --vercel <project> --review, then deploy again so the store reaches the site.',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
84
118
|
const APPEAR_MS = 2 * 60_000;
|
|
85
119
|
const BUILD_MS = 10 * 60_000;
|
|
86
120
|
/** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
|
|
@@ -14,8 +14,14 @@ export declare const linkedProject: (cwd: string) => string | null;
|
|
|
14
14
|
export declare const linkedOrg: (cwd: string) => string | null;
|
|
15
15
|
/** The variable names set for a target, read from `vercel env ls`'s table. */
|
|
16
16
|
export declare function envNames(cwd: string, target: Target): Set<string> | null;
|
|
17
|
-
/**
|
|
18
|
-
export declare function setEnv(cwd: string, name: string, target: Target, value: string
|
|
17
|
+
/** Adds one variable for one target that does not have it yet. */
|
|
18
|
+
export declare function setEnv(cwd: string, name: string, target: Target, value: string): Run | null;
|
|
19
|
+
/**
|
|
20
|
+
* What the gate needs that a target lacks, as `NAME:target`: the secret, and
|
|
21
|
+
* the review store, without which nobody can sign in, since it keeps the
|
|
22
|
+
* people and their links. Null when a target's names could not be read.
|
|
23
|
+
*/
|
|
24
|
+
export declare function missingGateEnv(names: Record<(typeof ENVIRONMENTS)[number], Set<string> | null>): string[] | null;
|
|
19
25
|
/** The gate variables missing from production or preview, or null when the CLI cannot say. */
|
|
20
26
|
export declare function gateEnvMissing(cwd: string): string[] | null;
|
|
21
27
|
/** The signed-in account, or null when the CLI is missing or signed out. */
|
|
@@ -6,7 +6,8 @@ import { spawnSync } from 'node:child_process';
|
|
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
export const ENVIRONMENTS = ['production', 'preview'];
|
|
9
|
-
|
|
9
|
+
/** What the gate needs: the secret that signs each person's session. */
|
|
10
|
+
const GATE_ENV = ['GATE_SECRET'];
|
|
10
11
|
/** What the Upstash for Redis integration injects (Vercel Marketplace). */
|
|
11
12
|
export const STORE_ENV = ['KV_REST_API_URL', 'KV_REST_API_TOKEN'];
|
|
12
13
|
export function vercel(cwd, args, input) {
|
|
@@ -36,24 +37,37 @@ export function envNames(cwd, target) {
|
|
|
36
37
|
return null;
|
|
37
38
|
return new Set([...out.stdout.matchAll(/^\s*([A-Z][A-Z0-9_]*)\s/gm)].map((m) => m[1]));
|
|
38
39
|
}
|
|
39
|
-
/**
|
|
40
|
-
export function setEnv(cwd, name, target, value
|
|
40
|
+
/** Adds one variable for one target that does not have it yet. */
|
|
41
|
+
export function setEnv(cwd, name, target, value) {
|
|
41
42
|
// The value goes on stdin, never argv, so it stays out of the process list.
|
|
42
|
-
return vercel(cwd, ['env', 'add', name, target,
|
|
43
|
+
return vercel(cwd, ['env', 'add', name, target, '--yes'], value);
|
|
43
44
|
}
|
|
44
|
-
/** The
|
|
45
|
-
|
|
45
|
+
/** The Upstash console's names for the same store; server/upstash.ts reads either pair. */
|
|
46
|
+
const UPSTASH_ENV = ['UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN'];
|
|
47
|
+
/**
|
|
48
|
+
* What the gate needs that a target lacks, as `NAME:target`: the secret, and
|
|
49
|
+
* the review store, without which nobody can sign in, since it keeps the
|
|
50
|
+
* people and their links. Null when a target's names could not be read.
|
|
51
|
+
*/
|
|
52
|
+
export function missingGateEnv(names) {
|
|
46
53
|
const missing = [];
|
|
47
54
|
for (const target of ENVIRONMENTS) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
55
|
+
const have = names[target];
|
|
56
|
+
if (!have)
|
|
50
57
|
return null;
|
|
51
58
|
for (const name of GATE_ENV)
|
|
52
|
-
if (!
|
|
59
|
+
if (!have.has(name))
|
|
53
60
|
missing.push(`${name}:${target}`);
|
|
61
|
+
const store = [STORE_ENV, UPSTASH_ENV].some((pair) => pair.every((n) => have.has(n)));
|
|
62
|
+
if (!store)
|
|
63
|
+
missing.push(...STORE_ENV.filter((n) => !have.has(n)).map((n) => `${n}:${target}`));
|
|
54
64
|
}
|
|
55
65
|
return missing;
|
|
56
66
|
}
|
|
67
|
+
/** The gate variables missing from production or preview, or null when the CLI cannot say. */
|
|
68
|
+
export function gateEnvMissing(cwd) {
|
|
69
|
+
return missingGateEnv({ production: envNames(cwd, 'production'), preview: envNames(cwd, 'preview') });
|
|
70
|
+
}
|
|
57
71
|
/** The signed-in account, or null when the CLI is missing or signed out. */
|
|
58
72
|
export function whoami(cwd) {
|
|
59
73
|
const out = vercel(cwd, ['whoami']);
|
package/dist/scripts/people.d.ts
CHANGED
|
@@ -2,58 +2,45 @@
|
|
|
2
2
|
import { type Args } from './lib/cli.ts';
|
|
3
3
|
export declare const spec: {
|
|
4
4
|
readonly name: 'people';
|
|
5
|
-
readonly summary: 'List
|
|
5
|
+
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.';
|
|
6
6
|
readonly positionals: [{
|
|
7
7
|
readonly name: 'action';
|
|
8
|
-
readonly description: 'list (default): everyone
|
|
8
|
+
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 project default, or sets it with --access.';
|
|
9
9
|
}, {
|
|
10
10
|
readonly name: 'id';
|
|
11
|
-
readonly description: 'The person, for
|
|
11
|
+
readonly description: 'The person, for link, sign-out, revoke and access';
|
|
12
12
|
}];
|
|
13
13
|
readonly flags: {
|
|
14
14
|
readonly name: {
|
|
15
15
|
readonly type: 'string';
|
|
16
|
-
readonly description: 'For
|
|
16
|
+
readonly description: 'For add: their name as it shows on comments.';
|
|
17
17
|
};
|
|
18
18
|
readonly team: {
|
|
19
19
|
readonly type: 'string';
|
|
20
|
-
readonly description: "For
|
|
20
|
+
readonly description: "For add: the studio, or the client's company.";
|
|
21
21
|
};
|
|
22
22
|
readonly kind: {
|
|
23
23
|
readonly type: 'string';
|
|
24
24
|
readonly default: 'client';
|
|
25
25
|
readonly choices: readonly ["studio", "client"];
|
|
26
|
-
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 and manages people.';
|
|
27
|
+
};
|
|
28
|
+
readonly access: {
|
|
29
|
+
readonly type: 'string';
|
|
30
|
+
readonly choices: readonly ["3m", "6m", "open"];
|
|
31
|
+
readonly description: 'How long they keep access: 3m, 6m or open. For add, absent means the project default for a client and open for studio.';
|
|
27
32
|
};
|
|
28
33
|
readonly site: {
|
|
29
34
|
readonly type: 'string';
|
|
30
|
-
readonly description: 'The deployed URL, so the
|
|
35
|
+
readonly description: 'The deployed URL, so the link prints whole.';
|
|
31
36
|
};
|
|
32
37
|
readonly local: {
|
|
33
38
|
readonly type: 'boolean';
|
|
34
39
|
readonly description: 'Use the local dev store even when the deployed one is configured.';
|
|
35
40
|
};
|
|
36
41
|
};
|
|
37
|
-
readonly output: '{ ok, store, people } or { ok, store, person, link }';
|
|
42
|
+
readonly output: '{ ok, store, people } or { ok, store, person, link } or { ok, store, person } or { ok, store, access }';
|
|
38
43
|
};
|
|
39
44
|
export declare function main({ positionals: [action, id], flags }: Args<typeof spec>): Promise<{
|
|
40
45
|
store: "deployed" | "local";
|
|
41
|
-
people: Omit<import("../core/review/model.ts").Person, "epoch">[];
|
|
42
|
-
person?: undefined;
|
|
43
|
-
} | {
|
|
44
|
-
link: string;
|
|
45
|
-
next: string;
|
|
46
|
-
people?: undefined;
|
|
47
|
-
store: "deployed" | "local";
|
|
48
|
-
person: Omit<import("../core/review/model.ts").Person, "epoch">;
|
|
49
|
-
} | {
|
|
50
|
-
next?: undefined;
|
|
51
|
-
link: string;
|
|
52
|
-
people?: undefined;
|
|
53
|
-
store: "deployed" | "local";
|
|
54
|
-
person: Omit<import("../core/review/model.ts").Person, "epoch">;
|
|
55
|
-
} | {
|
|
56
|
-
people?: undefined;
|
|
57
|
-
store: "deployed" | "local";
|
|
58
|
-
person: Omit<import("../core/review/model.ts").Person, "epoch">;
|
|
59
46
|
}>;
|