@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
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// The host port's Vercel adapter (scripts/lib/host.ts), through its CLI. Every call names the
|
|
3
|
+
// studio's team (`--scope`), so no command ever acts in whichever team the CLI
|
|
4
|
+
// last switched to. A call that acts through the folder's link (deploy, env,
|
|
5
|
+
// the stores) runs only once the link is the studio's project in that team,
|
|
6
|
+
// and the CLI never sees the env vars that would pick another. No call prints
|
|
7
|
+
// a value: secrets go in on stdin and come back only into the folder's `.env`.
|
|
8
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { hostName, proofPath } from '../../core/prototype.js';
|
|
12
|
+
import { readEnv } from '../../server/env.js';
|
|
13
|
+
import { CliError } from './cli.js';
|
|
14
|
+
import { upstashTerms } from './deploy.js';
|
|
15
|
+
import { BLOB_NAME, hasStore, STORE_NAMES } from './studios.js';
|
|
16
|
+
import { vercel } from './vercel.js';
|
|
17
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18
|
+
const HTTPS_TRIES = 20;
|
|
19
|
+
const HTTPS_GAP_MS = 3000;
|
|
20
|
+
/**
|
|
21
|
+
* A DELETE through `vercel api`. The CLI (59.x) asks before every DELETE and,
|
|
22
|
+
* with no terminal (as every design-hub command runs), refuses one unless it is
|
|
23
|
+
* told to skip that question. Only the two removals send it, each on a path
|
|
24
|
+
* built from a checked deployment id or host. `vercel remove` is not used: it
|
|
25
|
+
* also looks its argument up as a project and deletes any project it matches.
|
|
26
|
+
* No CLI command takes one host off one project (`vercel domains rm` takes the
|
|
27
|
+
* domain off the whole team).
|
|
28
|
+
*/
|
|
29
|
+
const DELETE = ['-X', 'DELETE', '--dangerously-skip-permissions'];
|
|
30
|
+
const DEPLOYMENT_ID = /^dpl_[A-Za-z0-9]+$/;
|
|
31
|
+
/** A Marketplace resource's name, as `vercel integration resource connect` takes it. */
|
|
32
|
+
const RESOURCE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
33
|
+
/** What the Marketplace answers a plan the team cannot have (studios-findings.md, section 5). */
|
|
34
|
+
const PLAN_NOT_FOUND = /billing plan not found|plan[^\n]*not (found|available)/i;
|
|
35
|
+
/**
|
|
36
|
+
* The plan the Marketplace labels exactly Free, from the plans its refusal of
|
|
37
|
+
* an unknown plan id lists (`Available plans: free_v3 (Free), launch_v3
|
|
38
|
+
* (Launch), …`), or null when it lists none so labelled.
|
|
39
|
+
*/
|
|
40
|
+
function freePlanOf(stderr) {
|
|
41
|
+
const listed = stderr.split(/Available plans:/i)[1]?.split(/\.\s|\n/)[0] ?? '';
|
|
42
|
+
for (const [, id, label] of listed.matchAll(/([A-Za-z0-9_-]+) \(([^)]*)\)/g))
|
|
43
|
+
if (label === 'Free')
|
|
44
|
+
return id;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/** The Marketplace product a new review store of each kind is made from, and its free plan's id as last seen. */
|
|
48
|
+
const MARKETPLACE = {
|
|
49
|
+
upstash: { product: 'upstash/upstash-kv', label: 'Upstash for Redis', plan: 'free' },
|
|
50
|
+
postgres: { product: 'neon', label: 'Neon Postgres', plan: 'free_v3' },
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Why no new free database was added: the free plan's id refused again (the
|
|
54
|
+
* team may still have one), no plan labelled Free (the team cannot have
|
|
55
|
+
* one), or anything else, most often the terms (addFailed).
|
|
56
|
+
*/
|
|
57
|
+
function notAdded(kind, stderr, free, team) {
|
|
58
|
+
const { label } = MARKETPLACE[kind];
|
|
59
|
+
const tail = stderr.trim().slice(-600);
|
|
60
|
+
const own = `If team ${team} has a database no studio uses (its Storage page on Vercel), run this again with --database <its name>.`;
|
|
61
|
+
if (!PLAN_NOT_FOUND.test(stderr))
|
|
62
|
+
return addFailed(kind, stderr, team);
|
|
63
|
+
if (free)
|
|
64
|
+
return new CliError(`The Marketplace did not take ${label}'s free plan (${free}); nothing was bought.`, {
|
|
65
|
+
stderr: tail,
|
|
66
|
+
fix: `Run this again in a few minutes. ${own}`,
|
|
67
|
+
});
|
|
68
|
+
return new CliError(`Team ${team} cannot have a free review store (${label}): the Marketplace offers it no free plan; nothing was bought.`, {
|
|
69
|
+
stderr: tail,
|
|
70
|
+
fix: `A database serves one studio only: never connect one another studio uses. ${own} Else give this studio a team or a ${label} account of its own.`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Why a new review store could not be added, most often terms the team has
|
|
75
|
+
* not accepted: for Upstash the words to send the user (upstashTerms), for
|
|
76
|
+
* Neon the link the CLI printed, else its Marketplace page.
|
|
77
|
+
*/
|
|
78
|
+
function addFailed(kind, stderr, team) {
|
|
79
|
+
const tail = stderr.trim().slice(-600);
|
|
80
|
+
const or = 'or connect a database the team has that no studio uses with --database <its name>.';
|
|
81
|
+
if (kind === 'upstash') {
|
|
82
|
+
const terms = upstashTerms(stderr, team);
|
|
83
|
+
return new CliError('Could not add the review store (Upstash for Redis) to the studio project.', {
|
|
84
|
+
stderr: tail,
|
|
85
|
+
terms: terms.url,
|
|
86
|
+
fix: `Most often the team has not accepted the Upstash terms. Tell the user, word for word: "${terms.say}" Then run this again; ${or}`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const url = stderr.match(/https:\/\/vercel\.com\/\S*accept-terms\S*/)?.[0] ?? 'https://vercel.com/marketplace/neon';
|
|
90
|
+
return new CliError('Could not add the review store (Neon Postgres) to the studio project.', {
|
|
91
|
+
stderr: tail,
|
|
92
|
+
terms: url,
|
|
93
|
+
fix: `Most often the team has not accepted the Neon terms. Tell the user, word for word: "Open ${url} for the ${team} team and accept the Neon terms. Stop once they are accepted: the rerun creates the database and connects it to this project." Then run this again; ${or}`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** The env vars the Vercel CLI (59.x) reads to pick a project or team over the folder's link and `--scope`. */
|
|
97
|
+
export const PICKERS = [
|
|
98
|
+
'VERCEL_ORG_ID',
|
|
99
|
+
'VERCEL_PROJECT_ID',
|
|
100
|
+
'NOW_ORG_ID',
|
|
101
|
+
'NOW_PROJECT_ID',
|
|
102
|
+
'VERCEL_TEAM_ID',
|
|
103
|
+
];
|
|
104
|
+
/** The caller's env without the names that would send a studio command to another project or team. */
|
|
105
|
+
function studioCliEnv(env) {
|
|
106
|
+
const out = { ...env };
|
|
107
|
+
for (const name of PICKERS)
|
|
108
|
+
delete out[name];
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
const studioCli = (cwd, args, input) => vercel(cwd, args, input, studioCliEnv(process.env));
|
|
112
|
+
/** The ids `.vercel/project.json` links the folder to, or none when it is missing or unreadable. */
|
|
113
|
+
function linkOf(dir) {
|
|
114
|
+
try {
|
|
115
|
+
return JSON.parse(readFileSync(join(dir, '.vercel', 'project.json'), 'utf8'));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** The Vercel adapter. Every call goes through `call`, which adds `--scope <team>`. */
|
|
122
|
+
export function vercelHost({ dir, team, project, run = studioCli, fetcher = fetch, wait = sleep, }) {
|
|
123
|
+
const call = (args, input) => {
|
|
124
|
+
const out = run(dir, [...args, '--scope', team], input);
|
|
125
|
+
if (!out)
|
|
126
|
+
throw new CliError('The Vercel CLI is not installed.', {
|
|
127
|
+
fix: 'npm i -g vercel, then design-hub signin.',
|
|
128
|
+
});
|
|
129
|
+
return out;
|
|
130
|
+
};
|
|
131
|
+
const must = (args, input) => {
|
|
132
|
+
const out = call(args, input);
|
|
133
|
+
if (out.status !== 0)
|
|
134
|
+
throw failed(args, out);
|
|
135
|
+
return out.stdout;
|
|
136
|
+
};
|
|
137
|
+
const api = async (path, method = 'GET', fields = []) => {
|
|
138
|
+
const verb = method === 'GET' ? [] : method === 'DELETE' ? DELETE : ['-X', method];
|
|
139
|
+
const args = ['api', path, '--raw', ...verb];
|
|
140
|
+
const out = call([...args, ...fields.flatMap((f) => ['-F', f])]);
|
|
141
|
+
if (out.status !== 0) {
|
|
142
|
+
if (/\b404\b|not[_ ]found/i.test(`${out.stdout}\n${out.stderr}`))
|
|
143
|
+
return null;
|
|
144
|
+
throw failed(['api', method, path], out);
|
|
145
|
+
}
|
|
146
|
+
return out.stdout.trim() ? JSON.parse(out.stdout) : {};
|
|
147
|
+
};
|
|
148
|
+
/** The studio's project on its team, as ids, or null when the team has none of that name. */
|
|
149
|
+
const studioProject = async () => {
|
|
150
|
+
const found = await api(`/v9/projects/${encodeURIComponent(project)}`);
|
|
151
|
+
return found ? { id: found.id, org: found.accountId } : null;
|
|
152
|
+
};
|
|
153
|
+
/** Whether `.vercel/project.json` is that project, in that team, by id: a name alone can be another team's. */
|
|
154
|
+
const linkedTo = (want) => {
|
|
155
|
+
const have = linkOf(dir);
|
|
156
|
+
return (!!want &&
|
|
157
|
+
typeof want.id === 'string' &&
|
|
158
|
+
typeof want.org === 'string' &&
|
|
159
|
+
have.projectId === want.id &&
|
|
160
|
+
have.orgId === want.org);
|
|
161
|
+
};
|
|
162
|
+
/** A call the CLI sends wherever the folder is linked: refused, before it runs, unless that is the studio. */
|
|
163
|
+
const linked = async (args, input) => {
|
|
164
|
+
if (!linkedTo(await studioProject()))
|
|
165
|
+
throw new CliError(`The studio folder is not linked to project ${project} in team ${team}; nothing was changed.`, {
|
|
166
|
+
dir,
|
|
167
|
+
fix: `design-hub studio link --dir ${dir}, then run this again.`,
|
|
168
|
+
});
|
|
169
|
+
return call(args, input);
|
|
170
|
+
};
|
|
171
|
+
const linkedMust = async (args, input) => {
|
|
172
|
+
const out = await linked(args, input);
|
|
173
|
+
if (out.status !== 0)
|
|
174
|
+
throw failed(args, out);
|
|
175
|
+
return out.stdout;
|
|
176
|
+
};
|
|
177
|
+
const names = async () => new Set([...(await linkedMust(['env', 'ls', 'production'])).matchAll(/^\s*([A-Z][A-Z0-9_]*)\s/gm)].map((m) => m[1]));
|
|
178
|
+
/**
|
|
179
|
+
* The team's database of this name, connected. One of another kind brings
|
|
180
|
+
* none of this kind's names: this run connected it, so this run lets it go.
|
|
181
|
+
*/
|
|
182
|
+
const connectExisting = async (kind, existing) => {
|
|
183
|
+
if (!RESOURCE_NAME.test(existing))
|
|
184
|
+
throw new CliError('--database takes the name of a database the team has.', { got: existing });
|
|
185
|
+
const out = await linked(['integration', 'resource', 'connect', existing, project, '--yes']);
|
|
186
|
+
if (out.status !== 0)
|
|
187
|
+
throw new CliError(`Could not connect the database ${existing} to the studio project.`, {
|
|
188
|
+
stderr: out.stderr.trim().slice(-600),
|
|
189
|
+
fix: `Check the name on team ${team}'s Storage page on Vercel, then run this again.`,
|
|
190
|
+
});
|
|
191
|
+
const now = await names();
|
|
192
|
+
if (hasStore(kind, (n) => now.has(n)))
|
|
193
|
+
return 'connected';
|
|
194
|
+
const gone = await disconnect(kind === 'upstash' ? 'postgres' : 'upstash', existing);
|
|
195
|
+
throw new CliError(`${existing} is not ${kind === 'upstash' ? 'an Upstash for Redis' : 'a Postgres'} database; ${gone ? 'it was disconnected again from' : 'it is still connected to'} project ${project}, and nothing was written to it.`, {
|
|
196
|
+
fix: gone
|
|
197
|
+
? `Run this again with --database <a ${kind} database the team has>, or without --database for a new free one.`
|
|
198
|
+
: `Disconnect ${existing} from project ${project} on team ${team}'s Storage page on Vercel, then run this again with --database <a ${kind} database the team has>, or without it.`,
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* A new database on the free plan only: a team without one is refused by
|
|
203
|
+
* the Marketplace, and nothing is bought. The plan id changes now and then,
|
|
204
|
+
* so a refused id is asked once more by the plan the Marketplace labels
|
|
205
|
+
* Free, never by another.
|
|
206
|
+
*/
|
|
207
|
+
const addFree = async (kind) => {
|
|
208
|
+
const { product, plan } = MARKETPLACE[kind];
|
|
209
|
+
const add = (id) => linked([
|
|
210
|
+
'integration',
|
|
211
|
+
'add',
|
|
212
|
+
product,
|
|
213
|
+
'--name',
|
|
214
|
+
`${project}-review`,
|
|
215
|
+
'--plan',
|
|
216
|
+
id,
|
|
217
|
+
'-e',
|
|
218
|
+
'production',
|
|
219
|
+
'--no-env-pull',
|
|
220
|
+
]);
|
|
221
|
+
let out = await add(plan);
|
|
222
|
+
const free = PLAN_NOT_FOUND.test(out.stderr) ? freePlanOf(out.stderr) : null;
|
|
223
|
+
if (out.status !== 0 && free && free !== plan)
|
|
224
|
+
out = await add(free);
|
|
225
|
+
if (out.status !== 0)
|
|
226
|
+
throw notAdded(kind, out.stderr, free, team);
|
|
227
|
+
return 'created';
|
|
228
|
+
};
|
|
229
|
+
/** Takes a team database off the project; true once Production holds none of the kind's names. */
|
|
230
|
+
const disconnect = async (kind, name) => {
|
|
231
|
+
if (!RESOURCE_NAME.test(name))
|
|
232
|
+
return false;
|
|
233
|
+
const out = await linked(['integration', 'resource', 'disconnect', name, project, '--yes']);
|
|
234
|
+
if (out.status !== 0)
|
|
235
|
+
return false;
|
|
236
|
+
const have = await names();
|
|
237
|
+
return !STORE_NAMES[kind].some((n) => have.has(n));
|
|
238
|
+
};
|
|
239
|
+
const domainPath = (host) => `/v9/projects/${encodeURIComponent(project)}/domains/${encodeURIComponent(host)}`;
|
|
240
|
+
return {
|
|
241
|
+
async link(create) {
|
|
242
|
+
const want = await studioProject();
|
|
243
|
+
if (linkedTo(want))
|
|
244
|
+
return 'kept';
|
|
245
|
+
if (create && want)
|
|
246
|
+
throw new CliError(`Team ${team} already has a project named ${project}.`, {
|
|
247
|
+
fix: 'Pick another --project, or run design-hub studio link on the folder that made it.',
|
|
248
|
+
});
|
|
249
|
+
if (!create && !want)
|
|
250
|
+
throw new CliError(`Team ${team} has no project named ${project}.`, {
|
|
251
|
+
fix: 'Check vercel.team and vercel.project in studio.json.',
|
|
252
|
+
});
|
|
253
|
+
if (create)
|
|
254
|
+
must(['project', 'add', project]);
|
|
255
|
+
must(['link', '--yes', '--project', project]);
|
|
256
|
+
if (!linkedTo(await studioProject()))
|
|
257
|
+
throw new CliError(`vercel link did not link the studio folder to project ${project} in team ${team}.`, {
|
|
258
|
+
dir,
|
|
259
|
+
fix: `Delete ${join(dir, '.vercel')}, then run this again.`,
|
|
260
|
+
});
|
|
261
|
+
return create ? 'created' : 'linked';
|
|
262
|
+
},
|
|
263
|
+
async hasEnv(name) {
|
|
264
|
+
return (await names()).has(name);
|
|
265
|
+
},
|
|
266
|
+
async setSecret(name, value) {
|
|
267
|
+
if ((await names()).has(name))
|
|
268
|
+
return 'kept';
|
|
269
|
+
await linkedMust(['env', 'add', name, 'production', '--sensitive', '--yes'], value);
|
|
270
|
+
return 'set';
|
|
271
|
+
},
|
|
272
|
+
async pullEnv(wanted) {
|
|
273
|
+
const tmp = mkdtempSync(join(tmpdir(), 'studio-env-'));
|
|
274
|
+
try {
|
|
275
|
+
await linkedMust(['env', 'pull', join(tmp, '.env'), '--environment=production', '--yes']);
|
|
276
|
+
const pulled = readEnv(tmp);
|
|
277
|
+
return Object.fromEntries(wanted.filter((n) => pulled[n]).map((n) => [n, pulled[n]]));
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
async provisionDatabase(kind, existing) {
|
|
284
|
+
const have = await names();
|
|
285
|
+
if (hasStore(kind, (n) => have.has(n)))
|
|
286
|
+
return 'kept';
|
|
287
|
+
const other = kind === 'upstash' ? 'postgres' : 'upstash';
|
|
288
|
+
const others = STORE_NAMES[other].filter((n) => have.has(n));
|
|
289
|
+
if (others.length)
|
|
290
|
+
throw new CliError(`Production on project ${project} holds another database's names (${others.join(', ')}), and the studio site refuses to guess between two; nothing was connected.`, {
|
|
291
|
+
fix: `On team ${team}'s Storage page on Vercel, disconnect that database from project ${project}, then run this again.`,
|
|
292
|
+
});
|
|
293
|
+
return existing === undefined ? addFree(kind) : connectExisting(kind, existing);
|
|
294
|
+
},
|
|
295
|
+
disconnectDatabase: (kind, name) => disconnect(kind, name),
|
|
296
|
+
async provisionFiles(region) {
|
|
297
|
+
if ((await names()).has(BLOB_NAME))
|
|
298
|
+
return 'kept';
|
|
299
|
+
await linkedMust([
|
|
300
|
+
'blob',
|
|
301
|
+
'create-store',
|
|
302
|
+
`${project}-files`,
|
|
303
|
+
'--access',
|
|
304
|
+
'private',
|
|
305
|
+
'--region',
|
|
306
|
+
region,
|
|
307
|
+
'--yes',
|
|
308
|
+
]);
|
|
309
|
+
return 'created';
|
|
310
|
+
},
|
|
311
|
+
async addDomain(host) {
|
|
312
|
+
const existing = await api(domainPath(host));
|
|
313
|
+
const state = existing === null
|
|
314
|
+
? await api(`/v10/projects/${encodeURIComponent(project)}/domains`, 'POST', [`name=${host}`])
|
|
315
|
+
: existing.verified
|
|
316
|
+
? existing
|
|
317
|
+
: await api(`${domainPath(host)}/verify`, 'POST');
|
|
318
|
+
return {
|
|
319
|
+
verified: state?.verified === true,
|
|
320
|
+
verification: state?.verification ?? existing?.verification ?? [],
|
|
321
|
+
};
|
|
322
|
+
},
|
|
323
|
+
async removeDomain(host) {
|
|
324
|
+
if (hostName(host) !== host)
|
|
325
|
+
throw new CliError(`${host} is not a host name; no domain was removed.`);
|
|
326
|
+
if ((await api(domainPath(host))) === null)
|
|
327
|
+
return 'absent';
|
|
328
|
+
await api(domainPath(host), 'DELETE');
|
|
329
|
+
return 'removed';
|
|
330
|
+
},
|
|
331
|
+
async recordFor(host) {
|
|
332
|
+
const config = await api(`/v6/domains/${encodeURIComponent(host)}/config?projectIdOrName=${encodeURIComponent(project)}`);
|
|
333
|
+
return cnameTarget(config);
|
|
334
|
+
},
|
|
335
|
+
async reaches(host, proof) {
|
|
336
|
+
for (let i = 0; i < HTTPS_TRIES; i++) {
|
|
337
|
+
if (await answers(fetcher, host, proof))
|
|
338
|
+
return true;
|
|
339
|
+
await wait(HTTPS_GAP_MS);
|
|
340
|
+
}
|
|
341
|
+
return false;
|
|
342
|
+
},
|
|
343
|
+
async deploy() {
|
|
344
|
+
const out = await linked(['deploy', '--prod', '--yes']);
|
|
345
|
+
const url = `${out.stdout}\n${out.stderr}`.match(/https:\/\/([\w.-]+\.vercel\.app)/)?.[1];
|
|
346
|
+
if (out.status !== 0 || !url)
|
|
347
|
+
throw failed(['deploy', '--prod'], out);
|
|
348
|
+
const found = await api(`/v13/deployments/${encodeURIComponent(url)}`);
|
|
349
|
+
if (!found?.id)
|
|
350
|
+
throw new CliError('The new deployment could not be read back.', {
|
|
351
|
+
fix: 'Run design-hub studio deploy again.',
|
|
352
|
+
});
|
|
353
|
+
return { id: String(found.id), state: String(found.readyState ?? found.status ?? '') };
|
|
354
|
+
},
|
|
355
|
+
async deployments() {
|
|
356
|
+
const all = [];
|
|
357
|
+
let until = '';
|
|
358
|
+
do {
|
|
359
|
+
const page = await api(`/v6/deployments?projectId=${encodeURIComponent(project)}&limit=100${until ? `&until=${until}` : ''}`);
|
|
360
|
+
for (const d of (page?.deployments ?? []))
|
|
361
|
+
all.push({ id: d.uid, state: String(d.state ?? d.readyState ?? '') });
|
|
362
|
+
until = page?.pagination?.next ? String(page.pagination.next) : '';
|
|
363
|
+
} while (until);
|
|
364
|
+
return all;
|
|
365
|
+
},
|
|
366
|
+
async removeDeployment(id) {
|
|
367
|
+
if (!DEPLOYMENT_ID.test(id))
|
|
368
|
+
throw new CliError(`${id} is not a deployment id; nothing was removed.`);
|
|
369
|
+
const out = call(['api', `/v13/deployments/${id}`, '--raw', ...DELETE]);
|
|
370
|
+
if (out.status !== 0)
|
|
371
|
+
throw new CliError(`Vercel would not delete the older deployment ${id}.`, {
|
|
372
|
+
stderr: out.stderr.trim().slice(-600),
|
|
373
|
+
fix: 'Delete it in the project’s Deployments page on Vercel, then run design-hub studio deploy again.',
|
|
374
|
+
});
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function failed(args, out) {
|
|
379
|
+
return new CliError(`vercel ${args.slice(0, 2).join(' ')} failed.`, {
|
|
380
|
+
stderr: out.stderr.trim().slice(-600),
|
|
381
|
+
fix: /log ?in|credentials|token|not authorized/i.test(out.stderr)
|
|
382
|
+
? 'design-hub signin, send the user its url, then run this again.'
|
|
383
|
+
: undefined,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
/** Vercel's first-ranked CNAME for a host, without its trailing dot. */
|
|
387
|
+
export function cnameTarget(config) {
|
|
388
|
+
const ranked = (config?.recommendedCNAME ?? [])
|
|
389
|
+
.slice()
|
|
390
|
+
.sort((a, b) => a.rank - b.rank);
|
|
391
|
+
const value = ranked[0]?.value?.replace(/\.$/, '').toLowerCase();
|
|
392
|
+
if (!value)
|
|
393
|
+
throw new CliError('Vercel named no record for this host.', { fix: 'Run this again in a minute.' });
|
|
394
|
+
return value;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* A host answers from this studio's site: asked the proof's path over HTTPS,
|
|
398
|
+
* it sends back the proof's answer, which only the gate reading this studio's
|
|
399
|
+
* store has. Any other answer, whatever its status or headers, is another
|
|
400
|
+
* server's, or a site that does not know the client yet.
|
|
401
|
+
*/
|
|
402
|
+
async function answers(fetcher, host, { ask, answer }) {
|
|
403
|
+
try {
|
|
404
|
+
const res = await fetcher(`https://${host}${proofPath(ask)}`, { redirect: 'manual' });
|
|
405
|
+
return res.status === 200 && (await res.text()) === answer;
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}
|
package/dist/scripts/people.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const spec: {
|
|
|
6
6
|
readonly summary: 'List or add the people who comment on the deployed prototypes, give them sign-in links, sign them out, revoke them, and set how long they keep access.';
|
|
7
7
|
readonly positionals: [{
|
|
8
8
|
readonly name: 'action';
|
|
9
|
-
readonly description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (the client’s own, else the studio’s
|
|
9
|
+
readonly description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (in a project the client’s own, else the studio’s; in the studio folder or with --studio the studio’s), or sets it with --access.';
|
|
10
10
|
}, {
|
|
11
11
|
readonly name: 'id';
|
|
12
12
|
readonly description: 'The person, for link, sign-out, revoke and access';
|
|
@@ -22,21 +22,24 @@ export declare const spec: {
|
|
|
22
22
|
};
|
|
23
23
|
readonly kind: {
|
|
24
24
|
readonly type: 'string';
|
|
25
|
-
readonly default: 'client';
|
|
26
25
|
readonly choices: readonly ["studio", "client"];
|
|
27
|
-
readonly description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts and
|
|
26
|
+
readonly description: 'client comments, replies and resolves any thread; studio also deletes any comment, sorts, manages people and sees every client at studio.<apex>. Absent: client in a project, studio in the studio folder or with --studio, which take studio only.';
|
|
28
27
|
};
|
|
29
28
|
readonly access: {
|
|
30
29
|
readonly type: 'string';
|
|
31
30
|
readonly choices: readonly ["3m", "6m", "open"];
|
|
32
31
|
readonly description: 'How long they keep access: 3m, 6m or open. For add, absent means the client’s default for a client (people access reads it) and open for studio.';
|
|
33
32
|
};
|
|
33
|
+
readonly studio: {
|
|
34
|
+
readonly type: 'string';
|
|
35
|
+
readonly description: 'The studio whose own people these are, by slug, from anywhere on this machine; in the studio folder it is that studio. Their links are on studio.<apex>. Client people are a project’s: run people in the project linked to their client.';
|
|
36
|
+
};
|
|
34
37
|
readonly local: {
|
|
35
38
|
readonly type: 'boolean';
|
|
36
39
|
readonly description: 'Use this machine’s dev store, even in a project linked to a studio.';
|
|
37
40
|
};
|
|
38
41
|
};
|
|
39
|
-
readonly output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; local otherwise';
|
|
42
|
+
readonly output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; store is studio with studio: { studio, host } for the studio’s own people (the studio folder or --studio); local otherwise. A Studio person’s link is on studio.<apex> once it answers.';
|
|
40
43
|
};
|
|
41
44
|
export declare function run({ positionals: [action, id], flags }: Args<typeof spec>, deps: ProjectDeps): Promise<Record<string, unknown>>;
|
|
42
45
|
export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
|