@milesroxas/design-hub 0.10.0 → 0.11.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 +13 -11
- package/core/files.test.ts +76 -0
- package/core/files.ts +131 -0
- package/core/prototype.test.ts +124 -7
- package/core/prototype.ts +133 -24
- package/core/review/model.ts +119 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1464 -340
- package/core/review/service.ts +777 -191
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -33
- package/dist/core/files.d.ts +39 -0
- package/dist/core/files.js +107 -0
- package/dist/core/prototype.d.ts +61 -12
- package/dist/core/prototype.js +105 -26
- package/dist/core/review/model.d.ts +76 -2
- package/dist/core/review/model.js +76 -1
- package/dist/core/review/policy.d.ts +11 -4
- package/dist/core/review/policy.js +14 -2
- package/dist/core/review/service.d.ts +197 -45
- package/dist/core/review/service.js +702 -192
- package/dist/core/review/store.d.ts +84 -31
- package/dist/core/review/store.js +66 -33
- package/dist/scripts/bootstrap.d.ts +4 -34
- package/dist/scripts/bootstrap.js +9 -244
- package/dist/scripts/cli.js +6 -0
- package/dist/scripts/client.d.ts +45 -0
- package/dist/scripts/client.js +320 -0
- package/dist/scripts/commands.js +6 -0
- package/dist/scripts/comments.d.ts +8 -26
- package/dist/scripts/comments.js +27 -14
- package/dist/scripts/lib/builds.d.ts +40 -0
- package/dist/scripts/lib/builds.js +198 -0
- package/dist/scripts/lib/cli.js +3 -1
- package/dist/scripts/lib/deploy.d.ts +6 -90
- package/dist/scripts/lib/deploy.js +24 -137
- package/dist/scripts/lib/dns.d.ts +49 -0
- package/dist/scripts/lib/dns.js +141 -0
- package/dist/scripts/lib/fake-host.d.ts +168 -0
- package/dist/scripts/lib/fake-host.js +244 -0
- package/dist/scripts/lib/host.d.ts +87 -0
- package/dist/scripts/lib/host.js +362 -0
- package/dist/scripts/lib/linked.d.ts +51 -0
- package/dist/scripts/lib/linked.js +124 -0
- package/dist/scripts/lib/names.d.ts +35 -0
- package/dist/scripts/lib/names.js +77 -0
- package/dist/scripts/lib/review.d.ts +23 -2
- package/dist/scripts/lib/review.js +32 -15
- package/dist/scripts/lib/studio-deps.d.ts +35 -0
- package/dist/scripts/lib/studio-deps.js +79 -0
- package/dist/scripts/lib/studios.d.ts +70 -0
- package/dist/scripts/lib/studios.js +187 -0
- package/dist/scripts/lib/update.d.ts +33 -0
- package/dist/scripts/lib/update.js +40 -0
- package/dist/scripts/lib/vercel.d.ts +1 -23
- package/dist/scripts/lib/vercel.js +6 -81
- package/dist/scripts/people.d.ts +7 -11
- package/dist/scripts/people.js +51 -46
- package/dist/scripts/preflight.d.ts +8 -1
- package/dist/scripts/preflight.js +36 -19
- package/dist/scripts/project.d.ts +86 -0
- package/dist/scripts/project.js +141 -0
- package/dist/scripts/share.d.ts +105 -30
- package/dist/scripts/share.js +82 -154
- package/dist/scripts/skills.d.ts +18 -2
- package/dist/scripts/skills.js +22 -3
- package/dist/scripts/studio.d.ts +75 -0
- package/dist/scripts/studio.js +401 -0
- package/dist/scripts/upgrade.d.ts +10 -2
- package/dist/scripts/upgrade.js +44 -14
- package/dist/server/api.d.ts +22 -11
- package/dist/server/api.js +114 -46
- package/dist/server/blob.d.ts +10 -0
- package/dist/server/blob.js +53 -0
- package/dist/server/checks.js +2 -2
- package/dist/server/dev.js +4 -4
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.js +9 -0
- package/dist/server/fake-upstash.js +52 -3
- package/dist/server/hosts.d.ts +11 -0
- package/dist/server/hosts.js +31 -0
- package/dist/server/local.d.ts +7 -1
- package/dist/server/local.js +10 -1
- package/dist/server/mark.d.ts +41 -0
- package/dist/server/mark.js +111 -0
- package/dist/server/session.d.ts +17 -9
- package/dist/server/session.js +22 -45
- package/dist/server/upstash.js +20 -0
- package/dist/vercel/files.d.ts +11 -0
- package/dist/vercel/files.js +68 -0
- package/dist/vercel/index.d.ts +4 -3
- package/dist/vercel/index.js +12 -8
- package/dist/vercel/proxy.d.ts +69 -4
- package/dist/vercel/proxy.js +171 -107
- package/dist/vite/plugin.d.ts +24 -1
- package/dist/vite/plugin.js +46 -2
- package/kit/dials.tsx +2 -2
- package/package.json +2 -1
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +1 -1
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +18 -3
- package/shell/review/Review.tsx +2 -2
- package/shell/review/ThreadCard.tsx +5 -5
- package/shell/review/client.ts +28 -11
- package/shell/review/view.test.ts +19 -0
- package/shell/review/view.ts +25 -0
- package/shell/shell.css +4 -0
- package/shell/studio/ClientHub.tsx +98 -0
- package/shell/studio/hub.css +48 -0
- package/shell/studio/index.html +14 -0
- package/shell/studio/main.tsx +17 -0
- package/skills/miles-deploy/SKILL.md +120 -65
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-review/SKILL.md +5 -7
- package/skills/miles-worktrees/SKILL.md +3 -3
- package/templates/conductor/settings.toml +1 -1
- package/templates/studio/.env.example +9 -0
- package/templates/studio/.vercelignore +5 -0
- package/templates/studio/README.md +84 -0
- package/templates/studio/_gitignore +7 -0
- package/templates/studio/api/files.ts +4 -0
- package/templates/studio/api/review.ts +4 -0
- package/templates/studio/build.mjs +4 -0
- package/templates/studio/package.json +16 -0
- package/templates/studio/proxy.ts +4 -0
- package/templates/studio/studio.json +9 -0
- package/templates/studio/vercel.json +27 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// A project's build into its studio's file store (studios.md, section 3,
|
|
3
|
+
// "How a build reaches the studio"). Every file of the built folder goes up
|
|
4
|
+
// under a new build id, `c/<client>/<project>/<build>/…`, and only once every
|
|
5
|
+
// file is up does the project's record point at it, so a share is atomic and
|
|
6
|
+
// a half-finished upload is never served. A share that fails part way removes
|
|
7
|
+
// what it uploaded and leaves the pointer where it was.
|
|
8
|
+
//
|
|
9
|
+
// Two rules keep one share from damaging another. The pointer moves to a
|
|
10
|
+
// build only once the store is read back holding every one of its files.
|
|
11
|
+
// And pruning removes only builds that are out of the running: each share
|
|
12
|
+
// starts its build in the studio's store first (startBuild), which numbers
|
|
13
|
+
// it, and setBuild refuses a build started before the live one. So once a
|
|
14
|
+
// build is live, every build started before it is out of the running, and
|
|
15
|
+
// the next prune removes all of them but the two that were live last; a
|
|
16
|
+
// build started after it may still go live, and stays. The order is the
|
|
17
|
+
// store's, never a machine's clock.
|
|
18
|
+
//
|
|
19
|
+
// What that does not cover: setBuild reads the pointer and then writes it,
|
|
20
|
+
// with no lock. Two shares of one project whose pointer steps run within the
|
|
21
|
+
// same few store calls can both pass its check, and the older build's write
|
|
22
|
+
// may land last. The project then shows the older build; and if the newer
|
|
23
|
+
// share pruned before the older one marked its build live, the older
|
|
24
|
+
// build's files are gone and the project answers 404. Either way the next
|
|
25
|
+
// share puts it right. Shares whose pointer steps do not overlap never do
|
|
26
|
+
// this, however long their uploads overlap.
|
|
27
|
+
import { randomBytes } from 'node:crypto';
|
|
28
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
29
|
+
import { join } from 'node:path';
|
|
30
|
+
import { buildPrefix, filePath, isBuildId, projectPrefix, removeAll, typeOf, } from '../../core/files.js';
|
|
31
|
+
import { isSegment } from '../../core/prototype.js';
|
|
32
|
+
import { CliError } from './cli.js';
|
|
33
|
+
/** How many builds of a project the store keeps: the live one and the two that were live before it. */
|
|
34
|
+
export const KEEP_BUILDS = 3;
|
|
35
|
+
/**
|
|
36
|
+
* A new build id: 16 random bytes in hex. Never a counter: 128 random bits
|
|
37
|
+
* mean an id never comes back for the life of the store, even for a project
|
|
38
|
+
* deleted and made again, so a path never comes back with other bytes.
|
|
39
|
+
* Inside the build-id rule (`[a-z0-9]{16,64}`, core/files.ts).
|
|
40
|
+
*/
|
|
41
|
+
export const newBuildId = () => randomBytes(16).toString('hex');
|
|
42
|
+
/**
|
|
43
|
+
* Every file under `dir` as a `/`-joined path, sorted. Dotfiles and anything
|
|
44
|
+
* in a dot folder are skipped: a build never serves one, and an editor's or
|
|
45
|
+
* a tool's leftovers (`.DS_Store`, `.vite/`) are not the project's.
|
|
46
|
+
*/
|
|
47
|
+
function filesUnder(dir, at = '') {
|
|
48
|
+
return readdirSync(join(dir, at), { withFileTypes: true })
|
|
49
|
+
.filter((entry) => !entry.name.startsWith('.'))
|
|
50
|
+
.flatMap((entry) => {
|
|
51
|
+
const path = at ? `${at}/${entry.name}` : entry.name;
|
|
52
|
+
if (entry.isDirectory())
|
|
53
|
+
return filesUnder(dir, path);
|
|
54
|
+
return entry.isFile() ? [path] : [];
|
|
55
|
+
})
|
|
56
|
+
.sort();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Removes everything under a build that never went live: whatever reached
|
|
60
|
+
* the store, a put that failed after it landed included. The id is new, so
|
|
61
|
+
* nothing else is under it. False when the store did not answer.
|
|
62
|
+
*/
|
|
63
|
+
async function dropBuild(files, scope, build) {
|
|
64
|
+
try {
|
|
65
|
+
await removeAll(files, await files.list(buildPrefix(scope, build)));
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
73
|
+
/**
|
|
74
|
+
* Points the project at the build, once the store is read back holding
|
|
75
|
+
* every one of its files. A write that failed may still have landed, so the
|
|
76
|
+
* record is read back: 'moved' when it names the build, 'stayed' when it
|
|
77
|
+
* names another, 'unknown' when it cannot be read.
|
|
78
|
+
*/
|
|
79
|
+
async function point({ review, files, actor }, scope, build, paths) {
|
|
80
|
+
try {
|
|
81
|
+
const held = new Set(await files.list(buildPrefix(scope, build)));
|
|
82
|
+
const missing = paths.filter((p) => !held.has(filePath(scope, build, p.split('/'))));
|
|
83
|
+
if (missing.length)
|
|
84
|
+
return { pointer: 'stayed', cause: `the store does not hold ${missing.length} of its files` };
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return { pointer: 'stayed', cause: `the store could not list its files: ${messageOf(error)}` };
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
await review.setBuild(scope, actor, build);
|
|
91
|
+
return { pointer: 'moved' };
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const now = await review.projectOf(scope).catch(() => undefined);
|
|
95
|
+
const cause = messageOf(error);
|
|
96
|
+
if (now === undefined)
|
|
97
|
+
return { pointer: 'unknown', cause };
|
|
98
|
+
return { pointer: now?.build === build ? 'moved' : 'stayed', cause };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Starts a build in the studio's store, uploads every file of `dist` under
|
|
103
|
+
* it, then points the project at it. A failed upload or pointer write
|
|
104
|
+
* removes the build and leaves the pointer as it was; only a pointer write
|
|
105
|
+
* whose result cannot be read back leaves the files, since they may be
|
|
106
|
+
* live. Returns the build id and how many files went up.
|
|
107
|
+
*/
|
|
108
|
+
export async function publishBuild(deps, scope, dist) {
|
|
109
|
+
const paths = filesUnder(dist);
|
|
110
|
+
if (!paths.length)
|
|
111
|
+
throw new CliError('The build has no files; nothing was uploaded.', { stage: 'build' });
|
|
112
|
+
const bad = paths.filter((p) => !p.split('/').every(isSegment));
|
|
113
|
+
if (bad.length)
|
|
114
|
+
throw new CliError('The build names files a studio cannot serve; nothing was uploaded.', {
|
|
115
|
+
stage: 'build',
|
|
116
|
+
files: bad.slice(0, 20),
|
|
117
|
+
fix: 'Rename them: a file name holds no control character, %, ?, # or backslash.',
|
|
118
|
+
});
|
|
119
|
+
const build = newBuildId();
|
|
120
|
+
try {
|
|
121
|
+
await deps.review.startBuild(scope, deps.actor, build);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new CliError(`The studio did not start the build; nothing was uploaded: ${messageOf(error)}`, {
|
|
125
|
+
stage: 'upload',
|
|
126
|
+
fix: 'Nothing changed for anyone who opens the project. Run share again.',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
let failure;
|
|
130
|
+
try {
|
|
131
|
+
for (const p of paths)
|
|
132
|
+
await deps.files.put(filePath(scope, build, p.split('/')), new Uint8Array(readFileSync(join(dist, p))), typeOf(p));
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
failure = error;
|
|
136
|
+
}
|
|
137
|
+
const { pointer, cause } = failure === undefined ? await point(deps, scope, build, paths) : { pointer: 'stayed' };
|
|
138
|
+
if (pointer === 'moved')
|
|
139
|
+
return { build, files: paths.length };
|
|
140
|
+
const removed = pointer === 'stayed' && (await dropBuild(deps.files, scope, build));
|
|
141
|
+
throw new CliError(failure === undefined
|
|
142
|
+
? `The build went up, but the project could not be pointed at it: ${cause}`
|
|
143
|
+
: `The upload failed: ${messageOf(failure)}`, {
|
|
144
|
+
stage: 'upload',
|
|
145
|
+
build,
|
|
146
|
+
pointer: pointer === 'unknown' ? 'unknown' : 'unchanged',
|
|
147
|
+
files: removed ? 'removed' : 'left',
|
|
148
|
+
fix: pointer === 'unknown'
|
|
149
|
+
? 'The store did not answer, so the files are left in case the project points at them. Run share again: it keeps the live build and removes old ones.'
|
|
150
|
+
: removed
|
|
151
|
+
? 'Nothing changed for anyone who opens the project. Run share again.'
|
|
152
|
+
: 'Nothing changed for anyone who opens the project, but some files of this build are left in the store; the next share removes them. Run share again.',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The builds pruning keeps: the live one, the two that were live before it,
|
|
157
|
+
* and every build started after it, which may still go live. Every other
|
|
158
|
+
* build was started before the live one, so setBuild refuses it, short of
|
|
159
|
+
* the overlap the head of this file names. With no live build known, every
|
|
160
|
+
* started build is kept.
|
|
161
|
+
*/
|
|
162
|
+
function kept(live, builds) {
|
|
163
|
+
const at = builds.find((b) => b.build === live);
|
|
164
|
+
if (!live || !at)
|
|
165
|
+
return new Set([...(live ? [live] : []), ...builds.map((b) => b.build)]);
|
|
166
|
+
const before = builds.filter((b) => b.n < at.n && b.live).slice(-(KEEP_BUILDS - 1));
|
|
167
|
+
return new Set([
|
|
168
|
+
live,
|
|
169
|
+
...before.map((b) => b.build),
|
|
170
|
+
...builds.filter((b) => b.n > at.n).map((b) => b.build),
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Deletes every build of the project that is out of the running but the two
|
|
175
|
+
* that were live last: partial builds of failed shares and shares overtaken
|
|
176
|
+
* by a newer one included, and files no started build names. Returns the
|
|
177
|
+
* builds whose files it removed.
|
|
178
|
+
*/
|
|
179
|
+
export async function pruneBuilds({ review, files, actor }, scope) {
|
|
180
|
+
const prefix = projectPrefix(scope);
|
|
181
|
+
// Listed before the builds are read: a build is started before its first file goes up, so every
|
|
182
|
+
// build listed here is among those read next, and one that is not named there never went up.
|
|
183
|
+
const byBuild = new Map();
|
|
184
|
+
for (const path of await files.list(prefix)) {
|
|
185
|
+
const build = path.slice(prefix.length).split('/')[0];
|
|
186
|
+
if (!isBuildId(build))
|
|
187
|
+
continue;
|
|
188
|
+
const paths = byBuild.get(build) ?? [];
|
|
189
|
+
paths.push(path);
|
|
190
|
+
byBuild.set(build, paths);
|
|
191
|
+
}
|
|
192
|
+
const { live, builds } = await review.buildsOf(scope, actor);
|
|
193
|
+
const keep = kept(live, builds);
|
|
194
|
+
const drop = [...byBuild.keys()].filter((b) => !keep.has(b)).sort();
|
|
195
|
+
await removeAll(files, drop.flatMap((b) => byBuild.get(b) ?? []));
|
|
196
|
+
await review.forgetBuilds(scope, actor, builds.map((b) => b.build).filter((b) => !keep.has(b)));
|
|
197
|
+
return drop;
|
|
198
|
+
}
|
package/dist/scripts/lib/cli.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// `{ ok: false, error, fix? }` with exit code 1. `design-hub commands` lists every
|
|
6
6
|
// schema, so an agent discovers the commands without reading their source.
|
|
7
7
|
import { parseArgs } from 'node:util';
|
|
8
|
+
import { MarkError } from '../../server/mark.js';
|
|
8
9
|
/** A failure the caller can act on: the message, and the fix when there is one. */
|
|
9
10
|
export class CliError extends Error {
|
|
10
11
|
detail;
|
|
@@ -76,8 +77,9 @@ export async function runCommand(spec, main, argv = process.argv.slice(2)) {
|
|
|
76
77
|
}
|
|
77
78
|
catch (error) {
|
|
78
79
|
// A domain error (the review service's) carries its problems by path; print them the same way.
|
|
80
|
+
// The store mark's refusal (server/mark.ts) carries a CliError's detail from a layer that cannot import it.
|
|
79
81
|
const problems = error?.problems;
|
|
80
|
-
const detail = error instanceof CliError
|
|
82
|
+
const detail = error instanceof CliError || error instanceof MarkError
|
|
81
83
|
? error.detail
|
|
82
84
|
: Array.isArray(problems) && problems.length
|
|
83
85
|
? { problems }
|
|
@@ -3,96 +3,6 @@ export declare function deviceLink(log: string): {
|
|
|
3
3
|
url: string;
|
|
4
4
|
code: string;
|
|
5
5
|
} | null;
|
|
6
|
-
/** The parts of `GET /v9/projects/<name>` a deploy reads. */
|
|
7
|
-
export type ProjectInfo = {
|
|
8
|
-
link?: {
|
|
9
|
-
type?: string;
|
|
10
|
-
repo?: string;
|
|
11
|
-
org?: string;
|
|
12
|
-
productionBranch?: string;
|
|
13
|
-
} | null;
|
|
14
|
-
targets?: {
|
|
15
|
-
production?: {
|
|
16
|
-
alias?: string[];
|
|
17
|
-
} | null;
|
|
18
|
-
} | null;
|
|
19
|
-
};
|
|
20
|
-
export declare const gitConnected: (info: ProjectInfo | null) => boolean;
|
|
21
|
-
/** The address a reviewer is sent: the first production alias (a custom domain when there is one). */
|
|
22
|
-
export declare function productionUrl(info: ProjectInfo | null, project: string): string;
|
|
23
|
-
export type Repo = {
|
|
24
|
-
connected: boolean;
|
|
25
|
-
branch: string | null;
|
|
26
|
-
productionBranch: string;
|
|
27
|
-
dirty: string[];
|
|
28
|
-
};
|
|
29
|
-
export type Plan = {
|
|
30
|
-
via: 'git';
|
|
31
|
-
branch: string;
|
|
32
|
-
} | {
|
|
33
|
-
via: 'cli';
|
|
34
|
-
reason: string;
|
|
35
|
-
} | {
|
|
36
|
-
error: string;
|
|
37
|
-
fix: string;
|
|
38
|
-
detail?: unknown;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* A project connected to its repo deploys by pushing the production branch, so
|
|
42
|
-
* the deployment matches a commit; otherwise the CLI uploads the folder.
|
|
43
|
-
* Pushing is refused from another branch or with uncommitted changes, since
|
|
44
|
-
* neither would deploy what is on disk.
|
|
45
|
-
*/
|
|
46
|
-
export declare function plan(repo: Repo, forceCli: boolean): Plan;
|
|
47
|
-
/**
|
|
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
|
-
*/
|
|
52
|
-
export declare const GATE_REQUEST: {
|
|
53
|
-
readonly redirect: 'manual';
|
|
54
|
-
readonly headers: {
|
|
55
|
-
readonly accept: 'text/html,application/xhtml+xml';
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
export type Answer = {
|
|
59
|
-
status: number;
|
|
60
|
-
location: string | null;
|
|
61
|
-
robots: string | null;
|
|
62
|
-
body: string;
|
|
63
|
-
};
|
|
64
|
-
export type Verdict = {
|
|
65
|
-
ok: true;
|
|
66
|
-
} | {
|
|
67
|
-
ok: false;
|
|
68
|
-
problem: string;
|
|
69
|
-
fix: string;
|
|
70
|
-
};
|
|
71
|
-
/** Whether the production URL answers a signed-out visitor with the hub's sign-in page. */
|
|
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;
|
|
81
|
-
export type Seen = {
|
|
82
|
-
url: string;
|
|
83
|
-
state: string;
|
|
84
|
-
} | null;
|
|
85
|
-
export type Next = {
|
|
86
|
-
done: string;
|
|
87
|
-
} | {
|
|
88
|
-
wait: true;
|
|
89
|
-
} | {
|
|
90
|
-
error: string;
|
|
91
|
-
fix: string;
|
|
92
|
-
deployment?: string;
|
|
93
|
-
};
|
|
94
|
-
/** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
|
|
95
|
-
export declare function nextStep(seen: Seen, sha: string, waitedMs: number): Next;
|
|
96
6
|
/**
|
|
97
7
|
* Where the user accepts the Upstash Marketplace terms for one team: the link the
|
|
98
8
|
* CLI printed when it has one, else that team's accept-terms page, else the
|
|
@@ -109,3 +19,9 @@ export declare function upstashTerms(stderr: string, team: string | undefined):
|
|
|
109
19
|
* the file goes back as it was, adding only `.vercel/` when it was missing.
|
|
110
20
|
*/
|
|
111
21
|
export declare function restoreGitignore(before: string, after: string): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
|
|
24
|
+
* when a step throws: `vercel link` appends to it, and a later failure (the
|
|
25
|
+
* Upstash terms, most often) would otherwise leave the tree dirty.
|
|
26
|
+
*/
|
|
27
|
+
export declare function keepingGitignore<T>(dir: string, steps: () => T | Promise<T>): Promise<T>;
|
|
@@ -1,146 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
// What `design-hub signin` and
|
|
3
|
-
//
|
|
4
|
-
// link in the CLI's log,
|
|
5
|
-
//
|
|
2
|
+
// What `design-hub signin` and the studio commands decide around the Vercel
|
|
3
|
+
// CLI, kept apart from the calls that feed them so every branch is tested:
|
|
4
|
+
// the sign-in link in the CLI's log, where the Upstash terms are accepted,
|
|
5
|
+
// and the .gitignore `vercel link` edits in a studio folder.
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
6
8
|
/** The device sign-in `vercel login` prints and then waits on. */
|
|
7
9
|
export function deviceLink(log) {
|
|
8
10
|
const m = log.match(/https:\/\/vercel\.com\/oauth\/device\?user_code=([A-Z0-9-]+)/);
|
|
9
11
|
return m ? { url: m[0], code: m[1] } : null;
|
|
10
12
|
}
|
|
11
|
-
export const gitConnected = (info) => Boolean(info?.link?.repo);
|
|
12
|
-
/** The address a reviewer is sent: the first production alias (a custom domain when there is one). */
|
|
13
|
-
export function productionUrl(info, project) {
|
|
14
|
-
const alias = info?.targets?.production?.alias?.find((a) => !a.includes('-git-')) ?? `${project}.vercel.app`;
|
|
15
|
-
return `https://${alias}`;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* A project connected to its repo deploys by pushing the production branch, so
|
|
19
|
-
* the deployment matches a commit; otherwise the CLI uploads the folder.
|
|
20
|
-
* Pushing is refused from another branch or with uncommitted changes, since
|
|
21
|
-
* neither would deploy what is on disk.
|
|
22
|
-
*/
|
|
23
|
-
export function plan(repo, forceCli) {
|
|
24
|
-
if (forceCli)
|
|
25
|
-
return { via: 'cli', reason: '--cli' };
|
|
26
|
-
if (!repo.connected)
|
|
27
|
-
return { via: 'cli', reason: 'the Vercel project is not connected to a Git repo' };
|
|
28
|
-
if (repo.branch !== repo.productionBranch)
|
|
29
|
-
return {
|
|
30
|
-
error: `On ${repo.branch ?? 'a detached HEAD'}; production deploys from ${repo.productionBranch}.`,
|
|
31
|
-
fix: `Merge into ${repo.productionBranch} and run this from there, or pass --cli to upload this folder as production.`,
|
|
32
|
-
};
|
|
33
|
-
if (repo.dirty.length)
|
|
34
|
-
return {
|
|
35
|
-
error: 'Uncommitted changes would not deploy.',
|
|
36
|
-
fix: 'Commit them (ask the user first), then run this again.',
|
|
37
|
-
detail: { dirty: repo.dirty.slice(0, 20) },
|
|
38
|
-
};
|
|
39
|
-
return { via: 'git', branch: repo.productionBranch };
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
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
|
-
*/
|
|
46
|
-
export const GATE_REQUEST = {
|
|
47
|
-
redirect: 'manual',
|
|
48
|
-
headers: { accept: 'text/html,application/xhtml+xml' },
|
|
49
|
-
};
|
|
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) {
|
|
55
|
-
if (answer.status >= 300 && answer.status < 400 && /vercel\.com/.test(answer.location ?? ''))
|
|
56
|
-
return {
|
|
57
|
-
ok: false,
|
|
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.',
|
|
60
|
-
};
|
|
61
|
-
if (answer.status === 503)
|
|
62
|
-
return {
|
|
63
|
-
ok: false,
|
|
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.',
|
|
66
|
-
};
|
|
67
|
-
if (answer.status !== 401)
|
|
68
|
-
return {
|
|
69
|
-
ok: false,
|
|
70
|
-
problem: `Expected the sign-in page (401), got ${answer.status}.`,
|
|
71
|
-
fix: 'Check that proxy.ts and vercel.json are the template’s, then deploy again.',
|
|
72
|
-
};
|
|
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))
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
problem: `The site answered 401, but the body was not the sign-in page: ${quote(answer.body)}.`,
|
|
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.',
|
|
91
|
-
};
|
|
92
|
-
if (!/noindex/.test(answer.robots ?? ''))
|
|
93
|
-
return {
|
|
94
|
-
ok: false,
|
|
95
|
-
problem: 'X-Robots-Tag: noindex is missing.',
|
|
96
|
-
fix: 'Restore vercel.json from the template.',
|
|
97
|
-
};
|
|
98
|
-
return { ok: true };
|
|
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
|
-
}
|
|
118
|
-
const APPEAR_MS = 2 * 60_000;
|
|
119
|
-
const BUILD_MS = 10 * 60_000;
|
|
120
|
-
/** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
|
|
121
|
-
export function nextStep(seen, sha, waitedMs) {
|
|
122
|
-
const deployment = seen ? `https://${seen.url}` : undefined;
|
|
123
|
-
if (seen?.state === 'READY')
|
|
124
|
-
return { done: `https://${seen.url}` };
|
|
125
|
-
if (seen && ['ERROR', 'CANCELED'].includes(seen.state))
|
|
126
|
-
return {
|
|
127
|
-
error: `The deployment of ${sha.slice(0, 7)} ended ${seen.state}.`,
|
|
128
|
-
fix: `vercel inspect ${deployment} --logs shows the build log.`,
|
|
129
|
-
deployment,
|
|
130
|
-
};
|
|
131
|
-
if (!seen && waitedMs > APPEAR_MS)
|
|
132
|
-
return {
|
|
133
|
-
error: `Vercel started no deployment for ${sha.slice(0, 7)}.`,
|
|
134
|
-
fix: 'Check the Git connection under Project Settings, Git, or run design-hub share --cli.',
|
|
135
|
-
};
|
|
136
|
-
if (waitedMs > BUILD_MS)
|
|
137
|
-
return {
|
|
138
|
-
error: 'The build is still running after 10 minutes.',
|
|
139
|
-
fix: 'Run design-hub share again once it finishes; nothing is pushed twice.',
|
|
140
|
-
deployment,
|
|
141
|
-
};
|
|
142
|
-
return { wait: true };
|
|
143
|
-
}
|
|
144
13
|
/**
|
|
145
14
|
* Where the user accepts the Upstash Marketplace terms for one team: the link the
|
|
146
15
|
* CLI printed when it has one, else that team's accept-terms page, else the
|
|
@@ -172,3 +41,21 @@ export function restoreGitignore(before, after) {
|
|
|
172
41
|
return before;
|
|
173
42
|
return `${before}${before.endsWith('\n') || !before ? '' : '\n'}.vercel/\n`;
|
|
174
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
|
|
46
|
+
* when a step throws: `vercel link` appends to it, and a later failure (the
|
|
47
|
+
* Upstash terms, most often) would otherwise leave the tree dirty.
|
|
48
|
+
*/
|
|
49
|
+
export async function keepingGitignore(dir, steps) {
|
|
50
|
+
const file = join(dir, '.gitignore');
|
|
51
|
+
const read = () => (existsSync(file) ? readFileSync(file, 'utf8') : '');
|
|
52
|
+
const before = read();
|
|
53
|
+
try {
|
|
54
|
+
return await steps();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
const kept = restoreGitignore(before, read());
|
|
58
|
+
if (kept !== null)
|
|
59
|
+
writeFileSync(file, kept);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DnsMode } from './studios.ts';
|
|
2
|
+
export type Ensured = 'added' | 'exists' | {
|
|
3
|
+
record: string;
|
|
4
|
+
};
|
|
5
|
+
/** What came off a host on archive: the records removed and the ones left, each `TYPE name content`; or the record for a person to remove. */
|
|
6
|
+
export type Released = {
|
|
7
|
+
removed: string[];
|
|
8
|
+
left: string[];
|
|
9
|
+
} | {
|
|
10
|
+
record: string;
|
|
11
|
+
};
|
|
12
|
+
export interface Dns {
|
|
13
|
+
mode: DnsMode;
|
|
14
|
+
ensure(host: string): Promise<Ensured>;
|
|
15
|
+
/** Takes the host's record off, once its client is archived: only one this studio made. */
|
|
16
|
+
release(host: string): Promise<Released>;
|
|
17
|
+
}
|
|
18
|
+
/** Where a host should point, from the host port (Vercel's first-ranked CNAME for it). */
|
|
19
|
+
type Target = (host: string) => Promise<string>;
|
|
20
|
+
/** The wildcard serves every host and stays: nothing to add or remove per host. */
|
|
21
|
+
export declare const wildcardDns: () => Dns;
|
|
22
|
+
export declare const manualDns: (target: Target) => Dns;
|
|
23
|
+
type DnsRecord = {
|
|
24
|
+
id?: string;
|
|
25
|
+
type: string;
|
|
26
|
+
name: string;
|
|
27
|
+
content: string;
|
|
28
|
+
proxied?: boolean;
|
|
29
|
+
comment?: string | null;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Whether the records already at a host are the one this studio needs: a
|
|
33
|
+
* single DNS-only CNAME to Vercel. Anything else (an A or AAAA record,
|
|
34
|
+
* another CNAME, a proxied one) is a person's to change, so it is refused
|
|
35
|
+
* with what is there, never overwritten.
|
|
36
|
+
*/
|
|
37
|
+
export declare function classify(found: DnsRecord[], target: string): 'exists';
|
|
38
|
+
type CloudflareOptions = {
|
|
39
|
+
token: string;
|
|
40
|
+
apex: string;
|
|
41
|
+
/** The zone id from studio.json, which saves a lookup; else found by the apex. */
|
|
42
|
+
zone: string | null;
|
|
43
|
+
/** Written on each record, so a person can tell which studio made it. */
|
|
44
|
+
studio: string;
|
|
45
|
+
target: Target;
|
|
46
|
+
fetcher?: typeof fetch;
|
|
47
|
+
};
|
|
48
|
+
export declare function cloudflareDns({ token, apex, zone, studio, target, fetcher, }: CloudflareOptions): Dns;
|
|
49
|
+
export {};
|