@milesroxas/design-hub 0.12.0 → 0.14.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.
Files changed (92) hide show
  1. package/README.md +5 -5
  2. package/core/prototype.test.ts +12 -1
  3. package/core/prototype.ts +21 -2
  4. package/core/review/model.ts +71 -6
  5. package/core/review/service.test.ts +575 -39
  6. package/core/review/service.ts +452 -25
  7. package/core/review/store.ts +47 -6
  8. package/core/review/suite-kv.ts +17 -0
  9. package/dist/core/prototype.d.ts +20 -2
  10. package/dist/core/prototype.js +17 -2
  11. package/dist/core/review/model.d.ts +42 -3
  12. package/dist/core/review/model.js +52 -3
  13. package/dist/core/review/service.d.ts +81 -7
  14. package/dist/core/review/service.js +407 -23
  15. package/dist/core/review/store.d.ts +29 -2
  16. package/dist/core/review/store.js +6 -2
  17. package/dist/core/review/suite-kv.d.ts +7 -0
  18. package/dist/core/review/suite-kv.js +12 -0
  19. package/dist/scripts/client.d.ts +1 -1
  20. package/dist/scripts/client.js +4 -4
  21. package/dist/scripts/lib/cli.js +5 -0
  22. package/dist/scripts/lib/dns.d.ts +16 -2
  23. package/dist/scripts/lib/dns.js +66 -3
  24. package/dist/scripts/lib/fake-host.d.ts +17 -3
  25. package/dist/scripts/lib/fake-host.js +56 -10
  26. package/dist/scripts/lib/host.d.ts +15 -25
  27. package/dist/scripts/lib/host.js +15 -324
  28. package/dist/scripts/lib/resend.d.ts +36 -0
  29. package/dist/scripts/lib/resend.js +66 -0
  30. package/dist/scripts/lib/studio-deps.d.ts +23 -0
  31. package/dist/scripts/lib/studio-deps.js +46 -16
  32. package/dist/scripts/lib/studios.d.ts +16 -6
  33. package/dist/scripts/lib/studios.js +28 -10
  34. package/dist/scripts/lib/vercel-host.d.ts +17 -0
  35. package/dist/scripts/lib/vercel-host.js +416 -0
  36. package/dist/scripts/people.d.ts +16 -4
  37. package/dist/scripts/people.js +67 -17
  38. package/dist/scripts/share.js +3 -2
  39. package/dist/scripts/studio.d.ts +26 -4
  40. package/dist/scripts/studio.js +364 -19
  41. package/dist/server/api.d.ts +20 -7
  42. package/dist/server/api.js +83 -27
  43. package/dist/server/dev.js +21 -1
  44. package/dist/server/gate.d.ts +120 -0
  45. package/dist/server/gate.js +808 -0
  46. package/dist/server/mailer.d.ts +60 -0
  47. package/dist/server/mailer.js +104 -0
  48. package/dist/server/mailers/fake.d.ts +8 -0
  49. package/dist/server/mailers/fake.js +16 -0
  50. package/dist/server/mailers/resend.d.ts +21 -0
  51. package/dist/server/mailers/resend.js +49 -0
  52. package/dist/server/mark.d.ts +17 -0
  53. package/dist/server/mark.js +46 -1
  54. package/dist/server/session.d.ts +2 -1
  55. package/dist/server/session.js +6 -3
  56. package/dist/server/stores/backends.d.ts +22 -0
  57. package/dist/server/stores/backends.js +96 -0
  58. package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
  59. package/dist/server/stores/index.d.ts +41 -0
  60. package/dist/server/stores/index.js +63 -0
  61. package/dist/server/stores/pglite.d.ts +16 -0
  62. package/dist/server/stores/pglite.js +98 -0
  63. package/dist/server/stores/postgres.d.ts +63 -0
  64. package/dist/server/stores/postgres.js +153 -0
  65. package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
  66. package/dist/vercel/files.js +1 -1
  67. package/dist/vercel/proxy.d.ts +6 -82
  68. package/dist/vercel/proxy.js +24 -524
  69. package/dist/vite/plugin.js +4 -2
  70. package/kit/ui/Menu.tsx +29 -18
  71. package/kit/ui/layer.ts +41 -0
  72. package/package.json +3 -1
  73. package/shell/review/Bar.tsx +1 -0
  74. package/shell/review/Card.tsx +17 -7
  75. package/shell/review/People.tsx +908 -134
  76. package/shell/review/Review.tsx +2 -2
  77. package/shell/review/anchor.ts +6 -1
  78. package/shell/review/client.ts +41 -7
  79. package/shell/review/menu-place.test.ts +41 -0
  80. package/shell/review/place.test.ts +26 -1
  81. package/shell/review/place.ts +17 -0
  82. package/shell/review/review.css +97 -11
  83. package/shell/review/view.test.ts +115 -1
  84. package/shell/review/view.ts +92 -2
  85. package/shell/studio/StudioHub.tsx +1 -0
  86. package/shell/studio/hub.css +99 -13
  87. package/skills/miles-deploy/SKILL.md +26 -4
  88. package/templates/studio/.env.example +9 -0
  89. package/templates/studio/README.md +13 -0
  90. package/templates/studio/package.json +1 -1
  91. /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
  92. /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
@@ -1,12 +1,14 @@
1
1
  // The one storage port the review service needs: a few Redis-shaped hash
2
- // and set operations. Production is Upstash Redis over REST
3
- // (server/upstash.ts); dev and tests use the in-memory store below, which
2
+ // and set operations. A studio's is Upstash Redis over REST or Postgres
3
+ // (server/stores/); dev and tests use the in-memory store below, which
4
4
  // the dev server persists to a file (server/file-kv.ts).
5
5
  import { SLUG } from '../feature.js';
6
6
  import { isClientSlug, isProjectSlug } from '../prototype.js';
7
7
  import { LOCAL_CLIENT } from './model.js';
8
8
  /** A comment's or a control's prototype: any kebab-case name, so reading one that is reserved finds nothing, as before. */
9
9
  const isKebab = (v) => typeof v === 'string' && SLUG.test(v);
10
+ /** A minute's number in a key: a whole count, never anything that could hold a `:`. */
11
+ const isCount = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
10
12
  /**
11
13
  * Every key the hub writes starts here, so a shared Redis never mixes it with
12
14
  * another app's data. Bumped when the stored shapes change without a
@@ -32,6 +34,8 @@ function part(ok, v, what) {
32
34
  const clientPrefix = (client) => `${PREFIX}c:${part(isClientSlug, client, 'client')}:`;
33
35
  const projectPrefix = (scope) => `${clientPrefix(scope.client)}p:${part(isProjectSlug, scope.project, 'project')}:`;
34
36
  export function keyOf(scope, name, prototype) {
37
+ if (scope === 'studio' && name === 'hits')
38
+ return `${PREFIX}studio:hits:${part(isCount, prototype, 'minute')}`;
35
39
  if (scope === 'studio')
36
40
  return DIRECTORY.includes(name) ? `${PREFIX}${name}` : `${PREFIX}studio:${name}`;
37
41
  if (!PROJECT_NAMES.includes(name))
@@ -0,0 +1,7 @@
1
+ import { type KV, type Snapshot } from './store.ts';
2
+ type Make = (initial?: Snapshot, onChange?: (s: Snapshot) => void) => KV;
3
+ /** A new store for one test, holding `initial`. */
4
+ export declare const suiteKV: Make;
5
+ /** For a test file that runs the service suite on another store: call before the suite loads. */
6
+ export declare function runSuiteOn(other: Make): void;
7
+ export {};
@@ -0,0 +1,12 @@
1
+ // The store the service suite (service.test.ts) runs on: the memory store,
2
+ // unless a test file picks another before it loads the suite, as
3
+ // server/stores/service.postgres.test.ts picks Postgres. One signature for
4
+ // both: the records to start with, and what to call after each write.
5
+ import { memoryKV } from './store.js';
6
+ let make = memoryKV;
7
+ /** A new store for one test, holding `initial`. */
8
+ export const suiteKV = (initial, onChange) => make(initial, onChange);
9
+ /** For a test file that runs the service suite on another store: call before the suite loads. */
10
+ export function runSuiteOn(other) {
11
+ make = other;
12
+ }
@@ -10,7 +10,7 @@ export declare const spec: {
10
10
  readonly description: 'add <slug>: the client, its host and its first person’s link (Studio opens it from studio.<apex>). list: every client, with its host, state and project count. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.';
11
11
  }, {
12
12
  readonly name: 'slug';
13
- readonly description: 'The client, kebab-case; never studio, www, api or site.';
13
+ readonly description: 'The client, kebab-case; never studio, www, api, mail or site.';
14
14
  }];
15
15
  readonly flags: {
16
16
  readonly studio: {
@@ -28,7 +28,7 @@ import { REUSE_SECONDS } from '../core/review/service.js';
28
28
  import { localStudio } from '../server/local.js';
29
29
  import { CliError } from './lib/cli.js';
30
30
  import { pointHost, waitServed } from './lib/dns.js';
31
- import { openReview, realDeps, recordOf } from './lib/studio-deps.js';
31
+ import { openFiles, openReview, realDeps, recordOf } from './lib/studio-deps.js';
32
32
  import { clientHost, findStudio, studioHost } from './lib/studios.js';
33
33
  /** S9: what a per-host or manual record makes public. */
34
34
  const PUBLIC_HOST = 'With per-host DNS a client’s host is public in certificate logs from the moment it is added. To keep the client’s name out of them, add it with --host <codename>.';
@@ -41,7 +41,7 @@ export const spec = {
41
41
  required: true,
42
42
  description: 'add <slug>: the client, its host and its first person’s link (Studio opens it from studio.<apex>). list: every client, with its host, state and project count. archive <slug>: remove it, its people, projects, comments and files, then its DNS record (only one this studio made) and its host on the site; run it again to finish one that stopped part way. An archived slug or host can be added again two minutes later. access [slug]: read or set (--access) the client’s default access length; without a slug, the studio’s.',
43
43
  },
44
- { name: 'slug', description: 'The client, kebab-case; never studio, www, api or site.' },
44
+ { name: 'slug', description: 'The client, kebab-case; never studio, www, api, mail or site.' },
45
45
  ],
46
46
  flags: {
47
47
  studio: { type: 'string', description: 'The studio’s slug. Absent, the studio folder this runs in.' },
@@ -171,7 +171,7 @@ async function add(ctx) {
171
171
  // while this one waited on the host, and its projects' builds are live.
172
172
  const current = await recordOf(review, slug);
173
173
  if (current && !isAdded(current))
174
- await clearPrefix(deps.files(studio), clientPrefix(slug));
174
+ await clearPrefix(await openFiles(deps, studio), clientPrefix(slug));
175
175
  await prove(ctx, host, client, dns);
176
176
  const at = (token) => `https://${client.host}/invite/${token}`;
177
177
  try {
@@ -234,7 +234,7 @@ async function archive(ctx) {
234
234
  // leaves the client readable; the record stays, archived, until they are done, so a run again
235
235
  // still knows the host and each step finds what is left.
236
236
  const archived = await review.archiveClient(scope, actor());
237
- const files = await clearPrefix(deps.files(studio), clientPrefix(slug));
237
+ const files = await clearPrefix(await openFiles(deps, studio), clientPrefix(slug));
238
238
  const record = archived?.client ?? null;
239
239
  const wildcard = studio.config.dns.mode === 'wildcard';
240
240
  // Another client's host, or one a live client's record names, is never taken off.
@@ -6,6 +6,7 @@
6
6
  // schema, so an agent discovers the commands without reading their source.
7
7
  import { parseArgs } from 'node:util';
8
8
  import { MarkError } from '../../server/mark.js';
9
+ import { closeStores } from '../../server/stores/index.js';
9
10
  /** A failure the caller can act on: the message, and the fix when there is one. */
10
11
  export class CliError extends Error {
11
12
  detail;
@@ -87,4 +88,8 @@ export async function runCommand(spec, main, argv = process.argv.slice(2)) {
87
88
  print({ ok: false, error: error instanceof Error ? error.message : String(error), ...detail });
88
89
  process.exitCode = 1;
89
90
  }
91
+ finally {
92
+ // A Postgres store's idle connections would keep the process up after its one JSON object.
93
+ await closeStores();
94
+ }
90
95
  }
@@ -11,11 +11,24 @@ export type Released = {
11
11
  } | {
12
12
  record: string;
13
13
  };
14
+ /** A record a mail domain needs, its name in full (`send.mail.example.com`). */
15
+ export type DnsRecord = {
16
+ type: 'TXT' | 'MX' | 'CNAME';
17
+ name: string;
18
+ value: string;
19
+ priority?: number;
20
+ };
21
+ /** What came of the records: all written, all there already, or each `TYPE name [priority] value` for a person to add. */
22
+ export type Recorded = 'added' | 'exists' | {
23
+ records: string[];
24
+ };
14
25
  export interface Dns {
15
26
  mode: DnsMode;
16
27
  ensure(host: string): Promise<Ensured>;
17
28
  /** Takes the host's record off, once its client is archived: only one this studio made. */
18
29
  release(host: string): Promise<Released>;
30
+ /** Puts these records in the apex's zone, or names them for a person to add. Never overwrites a record. */
31
+ records(wanted: DnsRecord[]): Promise<Recorded>;
19
32
  }
20
33
  /**
21
34
  * How a command that sets up a host says what to do next: `run` is the
@@ -52,11 +65,12 @@ type Target = (host: string) => Promise<string>;
52
65
  /** The wildcard serves every host and stays: nothing to add or remove per host. */
53
66
  export declare const wildcardDns: () => Dns;
54
67
  export declare const manualDns: (target: Target) => Dns;
55
- type DnsRecord = {
68
+ type CfRecord = {
56
69
  id?: string;
57
70
  type: string;
58
71
  name: string;
59
72
  content: string;
73
+ priority?: number;
60
74
  proxied?: boolean;
61
75
  comment?: string | null;
62
76
  };
@@ -66,7 +80,7 @@ type DnsRecord = {
66
80
  * another CNAME, a proxied one) is a person's to change, so it is refused
67
81
  * with what is there, never overwritten.
68
82
  */
69
- export declare function classify(found: DnsRecord[], target: string): 'exists';
83
+ export declare function classify(found: CfRecord[], target: string): 'exists';
70
84
  type CloudflareOptions = {
71
85
  token: string;
72
86
  apex: string;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
- // The DNS port: how a new client's host comes to point at the studio site.
3
- // Three adapters (studios-findings.md, sections 2 and 3):
2
+ // The DNS port: how a new client's host comes to point at the studio site,
3
+ // and how the records a mail domain needs reach the apex's zone (records,
4
+ // for `studio email`). Three adapters (studios-findings.md, sections 2 and 3):
4
5
  //
5
6
  // wildcard Vercel DNS: `*.<apex>` is on the studio project once, at
6
7
  // `studio create`, so every host already resolves; no call.
@@ -10,10 +11,17 @@
10
11
  // manual any other provider: the record, for a person to add, and on
11
12
  // archive, to remove.
12
13
  //
14
+ // A mail domain's records are written by Cloudflare's API alone; Vercel DNS
15
+ // and manual print them for a person to add (email.md, E11: Vercel DNS
16
+ // writes only once a real run there is recorded).
17
+ //
13
18
  // The Cloudflare token edits one zone's DNS. It lives in the studio folder's
14
19
  // gitignored `.env` and is sent only in the Authorization header; no error
15
20
  // here repeats it.
16
21
  import { CliError } from './cli.js';
22
+ /** A wanted record as a person adds it: `MX send.mail.example.com 10 feedback-smtp.example.net`. */
23
+ const recordLine = (r) => [r.type, r.name, ...(r.priority === undefined ? [] : [String(r.priority)]), r.value].join(' ');
24
+ const printed = async (wanted) => ({ records: wanted.map(recordLine) });
17
25
  const cap = (text) => text.charAt(0).toUpperCase() + text.slice(1);
18
26
  /**
19
27
  * Points a host at the studio site: its DNS record and, unless the wildcard
@@ -84,10 +92,11 @@ export const wildcardDns = () => ({
84
92
  mode: 'wildcard',
85
93
  ensure: async () => 'exists',
86
94
  release: async () => ({ removed: [], left: [] }),
95
+ records: printed,
87
96
  });
88
97
  export const manualDns = (target) => {
89
98
  const record = async (host) => ({ record: `CNAME ${host} ${await target(host)}` });
90
- return { mode: 'manual', ensure: record, release: record };
99
+ return { mode: 'manual', ensure: record, release: record, records: printed };
91
100
  };
92
101
  const CF = 'https://api.cloudflare.com/client/v4';
93
102
  /** What Vercel accepts a host pointing at: its own target, or the generic name. */
@@ -118,6 +127,24 @@ export function classify(found, target) {
118
127
  fix: `Point it at ${target} with one DNS-only CNAME at Cloudflare.`,
119
128
  });
120
129
  }
130
+ /** A value as Cloudflare holds it and as Resend gives it, read alike: a TXT without its quotes, any other without its last dot, in lower case. */
131
+ const readValue = (type, value) => type === 'TXT' ? value.replace(/^"(.*)"$/s, '$1') : bare(value);
132
+ /** The record at the name is the wanted one: its type, its value and, for an MX, its priority. */
133
+ const same = (want, have) => have.type === want.type &&
134
+ readValue(have.type, have.content) === readValue(want.type, want.value) &&
135
+ (want.type !== 'MX' || have.priority === want.priority);
136
+ /** A record the wanted one would stand beside wrongly: another of its type, a CNAME, or anything where a CNAME is wanted. */
137
+ const clashes = (want, have) => !same(want, have) && (want.type === 'CNAME' || have.type === 'CNAME' || have.type === want.type);
138
+ /** A mail record as Cloudflare takes it (email-findings.md, b): automatic TTL, a TXT in quotes, DNS-only, marked with the studio. */
139
+ const cfBody = (r, studio) => ({
140
+ type: r.type,
141
+ name: r.name,
142
+ content: r.type === 'TXT' ? `"${r.value}"` : r.value,
143
+ ttl: 1,
144
+ ...(r.priority === undefined ? {} : { priority: r.priority }),
145
+ ...(r.type === 'CNAME' ? { proxied: false } : {}),
146
+ comment: madeBy(studio),
147
+ });
121
148
  export function cloudflareDns({ token, apex, zone, studio, target, fetcher = fetch, }) {
122
149
  async function cf(path, init = {}) {
123
150
  const res = await fetcher(`${CF}${path}`, {
@@ -205,5 +232,41 @@ export function cloudflareDns({ token, apex, zone, studio, target, fetcher = fet
205
232
  }
206
233
  return { removed, left: found.filter((r) => !ours(r)).map(shown) };
207
234
  },
235
+ /**
236
+ * Adds each wanted record the zone lacks, after every name is looked up.
237
+ * A name holding a record that differs (another of the type, or a CNAME)
238
+ * stops it before anything is written: that record is a person's to
239
+ * change, never overwritten here, even one this studio made.
240
+ */
241
+ async records(wanted) {
242
+ const id = await zoneId();
243
+ const found = new Map();
244
+ for (const name of new Set(wanted.map((w) => bare(w.name))))
245
+ found.set(name, await look(id, name));
246
+ const at = (w) => found.get(bare(w.name)) ?? [];
247
+ const clashing = new Set(wanted.flatMap((w) => at(w)
248
+ .filter((h) => clashes(w, h))
249
+ .map(shown)));
250
+ if (clashing.size)
251
+ throw new CliError('The mail domain already has DNS records that differ from what Resend asks for; nothing was changed.', {
252
+ found: [...clashing],
253
+ wanted: wanted.map(recordLine),
254
+ fix: 'Remove those records at Cloudflare, or send from another domain under the apex, then run this again.',
255
+ });
256
+ const missing = wanted.filter((w) => !at(w).some((h) => same(w, h)));
257
+ for (const w of missing) {
258
+ const made = await cf(`/zones/${id}/dns_records`, {
259
+ method: 'POST',
260
+ body: JSON.stringify(cfBody(w, studio)),
261
+ });
262
+ if (!made.success)
263
+ throw new CliError('Cloudflare would not add a mail record.', {
264
+ record: recordLine(w),
265
+ errors: made.errors ?? [],
266
+ fix: 'Check that the token has DNS edit on the zone, then run this again.',
267
+ });
268
+ }
269
+ return missing.length ? 'added' : 'exists';
270
+ },
208
271
  };
209
272
  }
@@ -1,4 +1,5 @@
1
1
  import { type Review } from '../../core/review/service.ts';
2
+ import { type DnsRecord, type Recorded } from './dns.ts';
2
3
  import type { Deployment, DomainState, Host } from './host.ts';
3
4
  import type { StudioDeps } from './studio-deps.ts';
4
5
  export type FakeHost = {
@@ -21,8 +22,7 @@ export type FakeHost = {
21
22
  export declare function fakeHost(older?: string[]): FakeHost;
22
23
  /**
23
24
  * The studio site as a fetch from outside meets it, over the commands' own
24
- * store, answering as the gate does (vercel/proxy.ts, which `pnpm quality`
25
- * keeps scripts from importing): a host no client has is the plain 404, the
25
+ * store, answering as the gate does (server/gate.ts), in short: a host no client has is the plain 404, the
26
26
  * host proof's path answers the proof's answer for its ask, a link page is
27
27
  * 200 while the link is live and a POST uses it up, anything else is the
28
28
  * signed-out 401. It keeps each host's answer a minute, unknown hosts too,
@@ -109,6 +109,7 @@ export declare function fakeDeps(home: string, cwd?: string): {
109
109
  }>;
110
110
  revoke(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string): Promise<import("../../core/review/model.ts").Person>;
111
111
  setAccess(scope: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string, access: unknown): Promise<import("../../core/review/model.ts").Person>;
112
+ setEmail(at: import("../../core/review/service.ts").HostScope, actor: import("../../core/review/model.ts").Person | null, id: string, email: unknown): Promise<import("../../core/review/model.ts").Person>;
112
113
  defaultAccess(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
113
114
  setDefaultAccess(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, access: unknown): Promise<import("../../core/review/model.ts").Access>;
114
115
  addStudioPerson(actor: import("../../core/review/model.ts").Person | null, input: unknown): Promise<import("../../core/review/model.ts").Person>;
@@ -119,7 +120,16 @@ export declare function fakeDeps(home: string, cwd?: string): {
119
120
  studioAccess(actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Access>;
120
121
  setStudioAccess(actor: import("../../core/review/model.ts").Person | null, access: unknown): Promise<import("../../core/review/model.ts").Access>;
121
122
  peekLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
122
- useLink(at: import("../../core/review/service.ts").HostScope, token: string): Promise<import("../../core/review/model.ts").Person | null>;
123
+ useLink(at: import("../../core/review/service.ts").HostScope, token: string, browser?: string | null): Promise<import("../../core/review/model.ts").Person | null>;
124
+ askCode(at: import("../../core/review/service.ts").HostScope, email: unknown): Promise<{
125
+ person: import("../../core/review/model.ts").Person;
126
+ code: string;
127
+ hash: string;
128
+ } | null>;
129
+ hit(kind: import("../../core/review/service.ts").CapKind, address: string): Promise<boolean>;
130
+ recordMail(answer: import("../../core/review/service.ts").Sent): Promise<void>;
131
+ mailRecord(): Promise<import("../../core/review/service.ts").MailRecord>;
132
+ useCode(at: import("../../core/review/service.ts").HostScope, email: unknown, code: unknown, browser?: string | null): Promise<import("../../core/review/model.ts").Person | null>;
123
133
  listComments(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, prototype: string, viewAs?: unknown): Promise<import("../../core/review/model.ts").Comment[]>;
124
134
  allComments(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null): Promise<import("../../core/review/model.ts").Comment[]>;
125
135
  add(scope: import("../../core/review/model.ts").Scope, actor: import("../../core/review/model.ts").Person | null, input: {
@@ -180,6 +190,10 @@ export declare function fakeDeps(home: string, cwd?: string): {
180
190
  files: import("../../core/files.ts").Files;
181
191
  ensured: string[];
182
192
  released: string[];
193
+ recorded: DnsRecord[][];
194
+ records: {
195
+ answer: Recorded | Error;
196
+ };
183
197
  hosts: string[];
184
198
  clock: {
185
199
  at: number;
@@ -13,6 +13,15 @@ import { createReview } from '../../core/review/service.js';
13
13
  import { memoryKV } from '../../core/review/store.js';
14
14
  import { hostCache } from '../../server/hosts.js';
15
15
  import { manualDns, wildcardDns } from './dns.js';
16
+ import { hasStore, STORE_NAMES } from './studios.js';
17
+ /** What a new or connected database of each kind puts on the fake team's Production env. */
18
+ const DATABASES = {
19
+ upstash: { KV_REST_API_URL: 'https://kv.studio.test', KV_REST_API_TOKEN: 'kv-token-xxxxxxxx' },
20
+ postgres: {
21
+ DATABASE_URL: 'postgres://user:pg-secret-xxxxxxxx@db.studio.test/hub?sslmode=require',
22
+ POSTGRES_URL: 'postgres://user:pg-secret-xxxxxxxx@db.studio.test/hub?sslmode=require',
23
+ },
24
+ };
16
25
  export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
17
26
  let next = 0;
18
27
  const fake = {
@@ -47,6 +56,10 @@ export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
47
56
  fake.env.set(name, value);
48
57
  return 'set';
49
58
  },
59
+ async removeSecret(name) {
60
+ log(`removeSecret ${name}`);
61
+ return fake.env.delete(name) ? 'removed' : 'absent';
62
+ },
50
63
  async hasEnv(name) {
51
64
  log(`hasEnv ${name}`);
52
65
  return fake.env.has(name);
@@ -55,17 +68,17 @@ export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
55
68
  log(`pullEnv ${names.join(',')}`);
56
69
  return Object.fromEntries(names.filter((n) => fake.env.has(n)).map((n) => [n, fake.env.get(n)]));
57
70
  },
58
- async provisionDatabase(existing) {
59
- log(`provisionDatabase${existing ? ` ${existing}` : ''}`);
60
- if (fake.env.has('KV_REST_API_URL'))
71
+ async provisionDatabase(kind, existing) {
72
+ log(`provisionDatabase${kind === 'upstash' ? '' : ` ${kind}`}${existing ? ` ${existing}` : ''}`);
73
+ if (hasStore(kind, (n) => fake.env.has(n)))
61
74
  return 'kept';
62
- store({ KV_REST_API_URL: 'https://kv.studio.test', KV_REST_API_TOKEN: 'kv-token-xxxxxxxx' });
75
+ store(DATABASES[kind]);
63
76
  return existing ? 'connected' : 'created';
64
77
  },
65
- async disconnectDatabase(name) {
78
+ async disconnectDatabase(kind, name) {
66
79
  log(`disconnectDatabase ${name}`);
67
- fake.env.delete('KV_REST_API_URL');
68
- fake.env.delete('KV_REST_API_TOKEN');
80
+ for (const n of STORE_NAMES[kind])
81
+ fake.env.delete(n);
69
82
  return true;
70
83
  },
71
84
  async provisionFiles(region) {
@@ -119,8 +132,7 @@ export function fakeHost(older = ['dpl_old1', 'dpl_old2']) {
119
132
  const text = (status, body) => new Response(body, { status, headers: { 'content-type': 'text/plain; charset=utf-8' } });
120
133
  /**
121
134
  * The studio site as a fetch from outside meets it, over the commands' own
122
- * store, answering as the gate does (vercel/proxy.ts, which `pnpm quality`
123
- * keeps scripts from importing): a host no client has is the plain 404, the
135
+ * store, answering as the gate does (server/gate.ts), in short: a host no client has is the plain 404, the
124
136
  * host proof's path answers the proof's answer for its ask, a link page is
125
137
  * 200 while the link is live and a POST uses it up, anything else is the
126
138
  * signed-out 401. It keeps each host's answer a minute, unknown hosts too,
@@ -171,6 +183,9 @@ export function fakeDeps(home, cwd = home) {
171
183
  };
172
184
  const ensured = [];
173
185
  const released = [];
186
+ /** Each set of mail records the per-host DNS was asked for, and what it answers. */
187
+ const recorded = [];
188
+ const records = { answer: 'added' };
174
189
  const perHost = {
175
190
  mode: 'per-host',
176
191
  ensure: async (host) => {
@@ -181,6 +196,13 @@ export function fakeDeps(home, cwd = home) {
181
196
  released.push(host);
182
197
  return { removed: [`CNAME ${host} abc123.vercel-dns-016.com`], left: [] };
183
198
  },
199
+ records: async (wanted) => {
200
+ fake.calls.push(`dns records ${wanted.length}`);
201
+ recorded.push(wanted);
202
+ if (records.answer instanceof Error)
203
+ throw records.answer;
204
+ return records.answer;
205
+ },
184
206
  };
185
207
  /**
186
208
  * The host's DNS as its zone's nameservers and this machine's resolver see
@@ -227,6 +249,9 @@ export function fakeDeps(home, cwd = home) {
227
249
  : perHost,
228
250
  names,
229
251
  store: () => kv,
252
+ prepareStore: async () => {
253
+ fake.calls.push('prepareStore');
254
+ },
230
255
  now: () => new Date(clock.at),
231
256
  files: () => files,
232
257
  // Installs nothing: an install that passes writes the lockfile, as pnpm does.
@@ -242,6 +267,27 @@ export function fakeDeps(home, cwd = home) {
242
267
  writeFileSync(join(dir, 'pnpm-lock.yaml'), "lockfileVersion: '9.0'\n");
243
268
  return { status: 0, stdout: '', stderr: '' };
244
269
  },
270
+ // No mail key in a fake studio's .env: a test that mails sets one.
271
+ mailer: () => null,
272
+ // No network: a test that reaches Resend hands its own.
273
+ fetcher: async () => {
274
+ throw new Error('No network in the command tests.');
275
+ },
276
+ wait: async () => { },
277
+ };
278
+ return {
279
+ deps,
280
+ fake,
281
+ kv,
282
+ review,
283
+ files,
284
+ ensured,
285
+ released,
286
+ recorded,
287
+ records,
288
+ hosts,
289
+ clock,
290
+ pnpmFails,
291
+ dns,
245
292
  };
246
- return { deps, fake, kv, review, files, ensured, released, hosts, clock, pnpmFails, dns };
247
293
  }
@@ -1,4 +1,5 @@
1
- import { type Run } from './vercel.ts';
1
+ import type { StoreKind } from '../../server/stores/index.ts';
2
+ import type { StudioConfig } from './studios.ts';
2
3
  export type Deployment = {
3
4
  id: string;
4
5
  state: string;
@@ -22,25 +23,27 @@ export interface Host {
22
23
  link(create: boolean): Promise<'created' | 'linked' | 'kept'>;
23
24
  /** Sets a production secret that is not there yet, its value on stdin. */
24
25
  setSecret(name: string, value: string): Promise<'set' | 'kept'>;
26
+ /** Takes a production env var off, so a new value can be set in its place (setSecret keeps one there). */
27
+ removeSecret(name: string): Promise<'removed' | 'absent'>;
25
28
  /** Whether Production has an env var of this name; its value is never read. */
26
29
  hasEnv(name: string): Promise<boolean>;
27
30
  /** Production values of these names, read into memory, never into a file left behind. */
28
31
  pullEnv(names: readonly string[]): Promise<Record<string, string>>;
29
32
  /**
30
- * The review store (Upstash for Redis) when production has none: the
31
- * team's existing database of the name given, connected, or else a new
32
- * one, only ever on the free plan. A database serves one studio only:
33
- * `studio create` checks the one connected is no other studio's before it
34
- * writes to it (server/mark.ts).
33
+ * The review store of this kind (Upstash for Redis, or Postgres) when
34
+ * production has none: the team's existing database of the name given,
35
+ * connected, or else a new one, only ever on the free plan. A database
36
+ * serves one studio only: `studio create` checks the one connected is no
37
+ * other studio's before it writes to it (server/mark.ts).
35
38
  */
36
- provisionDatabase(existing?: string): Promise<'created' | 'connected' | 'kept'>;
39
+ provisionDatabase(kind: StoreKind, existing?: string): Promise<'created' | 'connected' | 'kept'>;
37
40
  /**
38
41
  * Takes the team's database of this name off the studio project, its
39
42
  * env vars with it, for a `studio create` that connected another studio's.
40
- * True once Production holds neither store name; false when the
41
- * disconnect failed or left them, so the refusal can say what is left.
43
+ * True once Production holds none of the kind's store names; false when
44
+ * the disconnect failed or left them, so the refusal can say what is left.
42
45
  */
43
- disconnectDatabase(name: string): Promise<boolean>;
46
+ disconnectDatabase(kind: StoreKind, name: string): Promise<boolean>;
44
47
  /** The private file store (Vercel Blob), made and connected when production has none. */
45
48
  provisionFiles(region: string): Promise<'created' | 'kept'>;
46
49
  /** Puts a host on the studio project, or asks Vercel to verify one already there. */
@@ -70,18 +73,5 @@ export declare function deployAlone(host: Host): Promise<{
70
73
  deployment: string;
71
74
  removed: string[];
72
75
  }>;
73
- type VercelOptions = {
74
- dir: string;
75
- team: string;
76
- project: string;
77
- run?: (cwd: string, args: string[], input?: string) => Run | null;
78
- fetcher?: typeof fetch;
79
- wait?: (ms: number) => Promise<unknown>;
80
- };
81
- /** The env vars the Vercel CLI (59.x) reads to pick a project or team over the folder's link and `--scope`. */
82
- export declare const PICKERS: string[];
83
- /** The Vercel adapter. Every call goes through `call`, which adds `--scope <team>`. */
84
- export declare function vercelHost({ dir, team, project, run, fetcher, wait, }: VercelOptions): Host;
85
- /** Vercel's first-ranked CNAME for a host, without its trailing dot. */
86
- export declare function cnameTarget(config: Record<string, any> | null): string;
87
- export {};
76
+ /** The host adapter a studio names, or a refusal that names the ones there are. */
77
+ export declare function hostFor(dir: string, config: StudioConfig, hosts?: Record<string, (dir: string, config: StudioConfig) => Host>): Host;