@milesroxas/design-hub 0.4.1 → 0.4.3

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.
@@ -56,6 +56,12 @@ export declare function ensurePort(): {
56
56
  claimed: boolean;
57
57
  warnings: string[];
58
58
  };
59
+ /**
60
+ * Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
61
+ * when a step throws: `vercel link` appends to it, and a later failure (the
62
+ * Upstash terms, most often) would otherwise leave the tree dirty.
63
+ */
64
+ export declare function keepingGitignore<T>(dir: string, steps: () => T): T;
59
65
  /** The gate's values: the password given, kept, or made, and the secret kept or made. */
60
66
  export declare function gateValues(given: string | undefined, env: Record<string, string>): {
61
67
  password: string;
@@ -11,7 +11,7 @@ import { join } from 'node:path';
11
11
  import { harnessPort, readEnv, writeEnv } from '../server/env.js';
12
12
  import { ROOT, TEMPLATES } from '../server/paths.js';
13
13
  import { CliError } from './lib/cli.js';
14
- import { gitConnected } from './lib/deploy.js';
14
+ import { gitConnected, restoreGitignore, upstashTerms } from './lib/deploy.js';
15
15
  import { holderOf, pickPort, readClaims, writeClaim } from './lib/ports.js';
16
16
  import { ENVIRONMENTS, envNames, linkedOrg, linkedProject, projectInfo, STORE_ENV, setEnv, vercel, whoami, } from './lib/vercel.js';
17
17
  export const spec = {
@@ -181,6 +181,24 @@ function link(project, team, warnings) {
181
181
  cli(['link', '--yes', '--project', project, ...(team ? ['--scope', team] : [])]);
182
182
  return 'ran';
183
183
  }
184
+ /**
185
+ * Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
186
+ * when a step throws: `vercel link` appends to it, and a later failure (the
187
+ * Upstash terms, most often) would otherwise leave the tree dirty.
188
+ */
189
+ export function keepingGitignore(dir, steps) {
190
+ const file = join(dir, '.gitignore');
191
+ const read = () => (existsSync(file) ? readFileSync(file, 'utf8') : '');
192
+ const before = read();
193
+ try {
194
+ return steps();
195
+ }
196
+ finally {
197
+ const kept = restoreGitignore(before, read());
198
+ if (kept !== null)
199
+ writeFileSync(file, kept);
200
+ }
201
+ }
184
202
  /** The `origin` remote, or null when the project has none. */
185
203
  function origin() {
186
204
  const out = spawnSync('git', ['-C', ROOT, 'remote', 'get-url', 'origin'], { encoding: 'utf8' });
@@ -281,11 +299,14 @@ function provisionReview(project, team, warnings) {
281
299
  // Unlike env and deploy, this command ignores the project link and takes the CLI's current team.
282
300
  ...scopeArgs(team),
283
301
  ]);
284
- if (out?.status !== 0)
285
- throw new CliError('Could not add the Upstash for Redis store.', {
302
+ if (out?.status !== 0) {
303
+ const terms = upstashTerms(out?.stderr ?? '', team);
304
+ throw new CliError('Could not add the Upstash for Redis store; most often the team has not accepted the Upstash terms yet.', {
286
305
  stderr: out?.stderr.trim().slice(-600),
287
- fix: `The Marketplace terms need accepting once per team: send the user https://vercel.com/marketplace/upstash to choose Install and accept for this team, then run this again.`,
306
+ terms: terms.url,
307
+ fix: `Tell the user, word for word: "${terms.say}" Then run this again.`,
288
308
  });
309
+ }
289
310
  store = 'created';
290
311
  }
291
312
  // The local commands (design-hub people, design-hub comments) read the same store.
@@ -379,8 +400,9 @@ export function main({ flags }) {
379
400
  };
380
401
  if (flags.conductor)
381
402
  result.conductor = writeConductor(flags.branch, warnings);
382
- if (flags.vercel)
383
- Object.assign(result, setUpVercel(flags.vercel, flags, env, typesafeKey, warnings));
403
+ const project = flags.vercel;
404
+ if (project)
405
+ Object.assign(result, keepingGitignore(ROOT, () => setUpVercel(project, flags, env, typesafeKey, warnings)));
384
406
  envIgnored(warnings);
385
407
  return { ...result, warnings };
386
408
  }
@@ -44,6 +44,17 @@ export type Plan = {
44
44
  * neither would deploy what is on disk.
45
45
  */
46
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. The gate
49
+ * answers a client that does not accept HTML with a plain-text 401, which has
50
+ * no password form 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
+ };
47
58
  export type Answer = {
48
59
  status: number;
49
60
  location: string | null;
@@ -74,3 +85,19 @@ export type Next = {
74
85
  };
75
86
  /** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
76
87
  export declare function nextStep(seen: Seen, sha: string, waitedMs: number): Next;
88
+ /**
89
+ * Where the user accepts the Upstash Marketplace terms for one team: the link the
90
+ * CLI printed when it has one, else that team's accept-terms page, else the
91
+ * product page. The page can list several Upstash products; the store is the one
92
+ * named here, and the rerun creates it, so nothing is created in the browser.
93
+ */
94
+ export declare function upstashTerms(stderr: string, team: string | undefined): {
95
+ url: string;
96
+ say: string;
97
+ };
98
+ /**
99
+ * `vercel link` appends `.vercel` and `.env*` to .gitignore. The template already
100
+ * ignores both, and `.env*` would hide `.env.example` and leave the tree dirty, so
101
+ * the file goes back as it was, adding only `.vercel/` when it was missing.
102
+ */
103
+ export declare function restoreGitignore(before: string, after: string): string | null;
@@ -38,6 +38,15 @@ export function plan(repo, forceCli) {
38
38
  };
39
39
  return { via: 'git', branch: repo.productionBranch };
40
40
  }
41
+ /**
42
+ * How `design-hub share` asks for the home page: as a browser does. The gate
43
+ * answers a client that does not accept HTML with a plain-text 401, which has
44
+ * no password form to find.
45
+ */
46
+ export const GATE_REQUEST = {
47
+ redirect: 'manual',
48
+ headers: { accept: 'text/html,application/xhtml+xml' },
49
+ };
41
50
  /** Whether the production URL answers a signed-out visitor with the hub's password page. */
42
51
  export function gateVerdict(answer) {
43
52
  if (answer.status >= 300 && answer.status < 400 && /vercel\.com/.test(answer.location ?? ''))
@@ -52,12 +61,18 @@ export function gateVerdict(answer) {
52
61
  problem: 'The gate answers 503: GATE_PASSWORD or GATE_SECRET is missing on the deployment.',
53
62
  fix: 'design-hub bootstrap --vercel <project>, then deploy again so the env reaches the site.',
54
63
  };
55
- if (answer.status !== 401 || !/name="password"/.test(answer.body))
64
+ if (answer.status !== 401)
56
65
  return {
57
66
  ok: false,
58
67
  problem: `Expected the password page (401), got ${answer.status}.`,
59
68
  fix: 'Check that proxy.ts and vercel.json are the template’s, then deploy again.',
60
69
  };
70
+ if (!/name="password"/.test(answer.body))
71
+ return {
72
+ ok: false,
73
+ problem: `The site answered 401, but the body was not the password page: ${JSON.stringify(answer.body.replace(/\s+/g, ' ').trim().slice(0, 80))}.`,
74
+ 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
+ };
61
76
  if (!/noindex/.test(answer.robots ?? ''))
62
77
  return {
63
78
  ok: false,
@@ -92,3 +107,34 @@ export function nextStep(seen, sha, waitedMs) {
92
107
  };
93
108
  return { wait: true };
94
109
  }
110
+ /**
111
+ * Where the user accepts the Upstash Marketplace terms for one team: the link the
112
+ * CLI printed when it has one, else that team's accept-terms page, else the
113
+ * product page. The page can list several Upstash products; the store is the one
114
+ * named here, and the rerun creates it, so nothing is created in the browser.
115
+ */
116
+ export function upstashTerms(stderr, team) {
117
+ const printed = stderr.match(/https:\/\/vercel\.com\/\S*accept-terms\S*/)?.[0];
118
+ const url = printed ??
119
+ (team
120
+ ? `https://vercel.com/${team}/~/integrations/accept-terms/upstash?source=cli`
121
+ : 'https://vercel.com/marketplace/upstash');
122
+ return {
123
+ url,
124
+ say: `Open ${url}${team ? ` for the ${team} team` : ''} and accept the Upstash terms. ` +
125
+ 'If it lists Upstash products, choose Install on Upstash for Redis (Redis Compatible Database), the only one Design Hub uses. ' +
126
+ 'Stop once the terms are accepted: close any step that offers to create a database, because the rerun creates the store and connects it to this project.',
127
+ };
128
+ }
129
+ /**
130
+ * `vercel link` appends `.vercel` and `.env*` to .gitignore. The template already
131
+ * ignores both, and `.env*` would hide `.env.example` and leave the tree dirty, so
132
+ * the file goes back as it was, adding only `.vercel/` when it was missing.
133
+ */
134
+ export function restoreGitignore(before, after) {
135
+ if (after === before)
136
+ return null;
137
+ if (/^\/?\.vercel\/?$/m.test(before))
138
+ return before;
139
+ return `${before}${before.endsWith('\n') || !before ? '' : '\n'}.vercel/\n`;
140
+ }
@@ -12,7 +12,7 @@ import { readEnv } from '../server/env.js';
12
12
  import { DOCS, ROOT } from '../server/paths.js';
13
13
  import { prototypes } from './lib/catalog.js';
14
14
  import { CliError } from './lib/cli.js';
15
- import { gateVerdict, gitConnected, nextStep, plan, productionUrl, } from './lib/deploy.js';
15
+ import { GATE_REQUEST, gateVerdict, gitConnected, nextStep, plan, productionUrl, } from './lib/deploy.js';
16
16
  import { linkedOrg, linkedProject, projectInfo, STORE_ENV, vercel, whoami } from './lib/vercel.js';
17
17
  import * as preflight from './preflight.js';
18
18
  export const spec = {
@@ -85,7 +85,7 @@ function viaCli() {
85
85
  /** A signed-out request for the home page, the way a reviewer first meets the link. */
86
86
  async function smoke(url) {
87
87
  try {
88
- const res = await fetch(`${url}/`, { redirect: 'manual' });
88
+ const res = await fetch(`${url}/`, GATE_REQUEST);
89
89
  return gateVerdict({
90
90
  status: res.status,
91
91
  location: res.headers.get('location'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -56,7 +56,7 @@ Signed in, it prints `signedIn: true` and the account. Signed out, it starts the
56
56
 
57
57
  ## Comments
58
58
 
59
- Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms: send the user the link in its `fix` to accept, then rerun. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first editor:
59
+ Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms. Send the user the message in its `fix` as written: it links that team's terms page, names the one product to pick (**Upstash for Redis**, Redis Compatible Database) when Vercel lists several, and tells them not to create a database there, since the rerun creates the store and connects it. Rerun when they say it is done; if `stderr` shows another cause, show it to them instead. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first editor:
60
60
 
61
61
  ```bash
62
62
  pnpm people invite --name "<user>" --team "<studio>" --role editor --site <share.url>
@@ -88,7 +88,7 @@ The user does nothing in a terminal here; each step that needs them is one link
88
88
 
89
89
  1. `pnpm --dir <path> signin`. Signed out, it prints a `url`: send it to the user to approve, then `pnpm --dir <path> signin --wait 300`.
90
90
  2. `vercel teams ls`; with more than one team, ask which with the question tool (personal account first when it is listed).
91
- 3. `pnpm --dir <path> bootstrap --vercel <name> --team <team-slug>`, plus `--review` for comments. It links the project, connects the GitHub repo, sets the password and turns Vercel's own login off. A first `--review` on a team can stop on the Marketplace terms: send the user the link in `fix`, then rerun.
91
+ 3. `pnpm --dir <path> bootstrap --vercel <name> --team <team-slug>`, plus `--review` for comments. It links the project, connects the GitHub repo, sets the password and turns Vercel's own login off. A first `--review` on a team can stop on the Marketplace terms: send the user the message in `fix` as written (it names **Upstash for Redis** as the product to pick), then rerun.
92
92
  4. `pnpm --dir <path> share --cli`. `--cli` uploads the folder, since the setup may have left files uncommitted; later deploys push `main`. On `ok: false`, follow `stage` and `fix` (the pre-flight steps are in `miles-deploy`).
93
93
  5. With comments: `pnpm --dir <path> people invite --name "<user>" --role editor --site <share.url>`.
94
94