@superintern/sites 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changes to @superintern/sites
2
2
 
3
+ ## 0.3.0
4
+
5
+ - `sites media add <file...>`: put large pictures, video, audio and PDFs in
6
+ a site's media files, outside its versions, up to 95 MB each. Each is
7
+ served at `/_media/<name>` on the site straight away; the command prints
8
+ that address. Three files go at a time, a dropped connection is tried once
9
+ more, and a file that is refused says why while the others still go.
10
+ - `sites media list` shows them and the room they take (`--json` too);
11
+ `sites media remove <name...>` deletes them. Inside a site's folder they
12
+ need no name; elsewhere add `--site <slug>`.
13
+ - `sites crm …` and `sites site …`: every tool of SuperIntern's MCP server
14
+ (the tools Claude is given) as a command, read from the service, so the two
15
+ always offer the same things. The CRM: tables, records, saved views and
16
+ automations, with changes, as far as your key's CRM access allows. Websites:
17
+ settings, history, media, redirects, analytics, traffic, search, removed
18
+ sites and more. A tool's arguments are its options; `--json` prints the
19
+ answer as it came. See `sites crm --help` and `sites site --help`.
20
+ - `list`, `status`, `publish`, `unpublish`, `remove`, `open`, `accounts`,
21
+ `new` and `clone` work as before, through the same tools.
22
+
3
23
  ## 0.2.0
4
24
 
5
25
  - `sites accounts`: whether customers can sign in to a site, and how
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # sites
2
2
 
3
3
  Make a website for a business on SuperIntern, see how it is doing, and put it
4
- online, from your own computer.
4
+ online, from your own computer. Work on the business's CRM too: its tables
5
+ and records, and everything else SuperIntern's tools for Claude can do.
5
6
 
6
7
  A site is a folder of ordinary files that you edit, with git keeping its
7
8
  history. `sites` makes the site, brings its files to your computer, tells you
@@ -83,22 +84,61 @@ sites rows <table> [<name>] the first rows of one of those tables
83
84
  sites accounts [<name>] whether customers can sign in, and how
84
85
  sites accounts [<name>] --sign-in on --passwords on
85
86
  let customers sign in, with a password too
87
+ sites media add <file...> put large pictures, video, audio and PDFs on the site
88
+ sites media list the site's media files and the room they take
89
+ sites media remove <name...> delete media files
86
90
  sites link in a site's folder: tie it to this copy of sites
91
+ sites crm <command> [options] the business's CRM: tables, records, views, automations
92
+ sites site <command> [options] every other website tool: settings, history, media,
93
+ redirects, analytics, traffic, search and more
87
94
  sites --version which version of sites this is
88
95
  sites --help every option
89
96
  ```
90
97
 
91
98
  A site's name is 3 to 40 lowercase letters, digits and single hyphens. It
92
99
  becomes the site's address. Inside a site's folder, `status`, `tables`,
93
- `rows` and `accounts` need no name.
100
+ `rows`, `accounts` and `media` need no name.
94
101
 
95
102
  `sites status --wait` ends with exit code 0 when your push was built and is
96
103
  ready to publish, 1 when it failed (what to fix is printed), and 2 when it
97
104
  took too long.
98
105
 
106
+ A site's own files are at most 25 MB each, and 25 MB together once zipped.
107
+ Large pictures, video, audio and PDFs (up to 95 MB each) go in its media
108
+ files instead: `sites media add photos/*.jpg tour.mp4` prints the address
109
+ each file got, such as `/_media/tour.mp4`, which pages use like any other
110
+ file. Media files are not part of a version: they are on the site as soon as
111
+ they are added, and publishing does not change them.
112
+
99
113
  To go back to an earlier version: `sites status` shows the numbers, then
100
114
  `sites publish <name> --version <n>`.
101
115
 
116
+ ## The CRM, and every other tool
117
+
118
+ `sites crm` and `sites site` are SuperIntern's tools for Claude, the same
119
+ ones, read from the service each time: whatever your key may do, these
120
+ commands can do. See them with `sites crm --help` and `sites site --help`,
121
+ and one command's options with `--help` after it.
122
+
123
+ ```bash
124
+ sites crm table-list
125
+ sites crm table-save "Bike sizes" --create --columns '[{"title": "Frame", "type": "text", "visibility": "public"}]'
126
+ sites crm record-save "Bike sizes" --records '[{"name": "Small", "values": {"frame": "48 cm"} }]'
127
+ sites crm record-search "Bike sizes" --json
128
+ sites site history-read my-shop
129
+ sites site redirect-read
130
+ ```
131
+
132
+ Each of a tool's arguments is an option with the same name, hyphens for
133
+ underscores. A list or an object is written as JSON (or `@file.json`), and
134
+ `--input` takes all the arguments as one JSON object. In a site's folder,
135
+ `sites site` commands need no site name. `--json` prints the service's answer
136
+ as it came.
137
+
138
+ What the CRM commands may do is the CRM access chosen on your key. A key that
139
+ may not change the CRM says so; make one that may (Website, Keys) and run
140
+ `sites login` again.
141
+
102
142
  ## When a push is refused
103
143
 
104
144
  | Git says | What to do |
@@ -116,7 +156,7 @@ To go back to an earlier version: `sites status` shows the numbers, then
116
156
  for it: a command line is kept in your shell's history.
117
157
  - It is kept in your macOS keychain, or elsewhere in the file
118
158
  `~/.config/superintern-sites/<service>.key`, which only you can read.
119
- - It is sent to two addresses only, always over https: SuperIntern's site
159
+ - It is sent to two addresses only, always over https: SuperIntern's
120
160
  service and its git address (below). It is never printed.
121
161
  - Those two addresses change only if you set `SUPERINTERN_SITES_API_BASE` or
122
162
  `SUPERINTERN_SITES_GIT_BASE` yourself, which is for running against a
@@ -134,7 +174,7 @@ To go back to an earlier version: `sites status` shows the numbers, then
134
174
 
135
175
  | | Test service (the default today) | Production (`--env prod`, not open yet) |
136
176
  |---|---|---|
137
- | Site service | `https://test-api.superintern.ai` | `https://api.superintern.ai` |
177
+ | Service | `https://test-api.superintern.ai` | `https://api.superintern.ai` |
138
178
  | Git address | `https://git.testforstuff.com` | `https://git.superintern.app` |
139
179
  | A site's address | `https://<name>.testforstuff.com` | `https://<name>.superintern.app` |
140
180
 
package/bin/sites.mjs CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- // sites: make a site, see how it is doing, and put it online.
3
- // It talks to the site API and to the git address, and to nothing else.
2
+ // sites: make a site, see how it is doing, and put it online; and every tool
3
+ // of SuperIntern's MCP server, the same ones Claude is given (`sites crm …`,
4
+ // `sites site …`). It talks to the service (its MCP server and site API) and
5
+ // to the git address, and to nothing else.
4
6
 
5
7
  import { spawn } from "node:child_process";
6
8
  import { fileURLToPath } from "node:url";
@@ -13,6 +15,7 @@ import { runGit } from "../src/cli/git.mjs";
13
15
  import { defaultKeyStore } from "../src/cli/keys.mjs";
14
16
  import { PACKAGE_VERSION } from "../src/cli/package-info.mjs";
15
17
  import { readLine, readSecret } from "../src/cli/prompt.mjs";
18
+ import { GROUPS } from "../src/cli/tools.mjs";
16
19
 
17
20
  const USAGE = `Usage:
18
21
  sites login Save your key (you are asked for it; it is not shown)
@@ -32,16 +35,35 @@ const USAGE = `Usage:
32
35
  sites accounts [<slug>] --sign-in on|off [--passwords on|off]
33
36
  Switch customer accounts (and passwords, --google,
34
37
  --microsoft) on or off
38
+ sites media add <file...> Put large pictures, video, audio and PDFs in the
39
+ site's media files, served at /_media/<name>
40
+ sites media list The site's media files, and the room they take
41
+ sites media remove <name...> Delete media files
35
42
  sites link In a site's folder: tie it to this copy of sites
43
+ sites crm <command> [options] The business's CRM: tables, records, saved views and
44
+ automations. See them all: sites crm --help
45
+ sites site <command> [options] Everything else about websites: settings, history,
46
+ media, redirects, analytics, traffic, search and more.
47
+ See them all: sites site --help
36
48
  sites logout Remove your saved key
37
49
  sites --version Which version of sites this is
38
50
 
39
- In a site's folder, status, tables, rows and accounts need no <slug>. A table is named by its
51
+ In a site's folder, status, tables, rows, accounts and media need no <slug>. A table is named by its
40
52
  name (in quotes when it has a space), its slug or its id.
41
53
 
54
+ \`sites crm\` and \`sites site\` are SuperIntern's MCP tools, the same ones Claude
55
+ is given, read from the service: what your key may do decides which you can use.
56
+ Each tool's arguments are its options (\`sites crm record-save --help\`); a list or
57
+ an object is given as JSON. --json prints the service's answer as it came.
58
+
42
59
  A push never changes the live site. After a push, the site is built and
43
60
  checked; \`sites publish\` puts the result online.
44
61
 
62
+ A site's own files are at most 25 MB each and 25 MB together, zipped. Large
63
+ pictures, video, audio and PDFs go in its media files instead
64
+ (\`sites media add\`): up to 95 MB each, kept outside its versions, and on the
65
+ site straight away at /_media/<name>.
66
+
45
67
  Options:
46
68
  --env <test|prod> Which service to use. Default: ${DEFAULT_ENVIRONMENT}.
47
69
  --name <name> With new: what the business is called.
@@ -54,10 +76,11 @@ Options:
54
76
  --timeout <seconds> With status --wait: how long to wait. Default: 900.
55
77
  --limit <n> With rows: how many rows to show. Default: 5. At most 50.
56
78
  --site <slug> With tables and rows: the site, the same as naming it
57
- after the command.
79
+ after the command. With media: the site.
58
80
  --sign-in, --passwords, --google, --microsoft <on|off>
59
81
  With accounts: what to switch. Only what is given changes.
60
- --json With list, status and accounts: print everything as JSON.
82
+ --json With list, status, accounts and media list: print everything
83
+ as JSON.
61
84
  With tables and rows: print the service's reply.
62
85
  --no-check With login: save the key without checking it.
63
86
  --yes With remove: don't ask to type the site's name. For scripts.
@@ -78,6 +101,14 @@ async function main() {
78
101
  return 0;
79
102
  }
80
103
 
104
+ // `sites crm …` and `sites site …` take the options of the tool they name.
105
+ const invocation = toolInvocation(typed);
106
+ if (invocation) {
107
+ const environment = resolveEnvironment(invocation.env);
108
+ if (environment.overridden) console.error(`Using ${environment.api} and ${environment.git} (set by SUPERINTERN_SITES_API_BASE / SUPERINTERN_SITES_GIT_BASE).`);
109
+ return commands.tool(context(environment), invocation.group, invocation.rest, { json: invocation.json, help: invocation.help });
110
+ }
111
+
81
112
  const { values, positionals } = parseArgs({
82
113
  allowPositionals: true,
83
114
  options: {
@@ -107,28 +138,12 @@ async function main() {
107
138
  }
108
139
  // Quietly ignoring it would show one site to someone who named another.
109
140
  if (values.site !== undefined && !TAKES_SITE.has(command)) {
110
- throw new Error(`\`sites ${command}\` does not take --site: it goes with tables, rows and data-token only.`);
141
+ throw new Error(`\`sites ${command}\` does not take --site: it goes with tables, rows, media and data-token only.`);
111
142
  }
112
143
 
113
144
  const environment = resolveEnvironment(values.env);
114
- /** @type {commands.Context} */
115
- const ctx = {
116
- environment,
117
- keys: defaultKeyStore(),
118
- api: (key) => createApi({ base: environment.api, key }),
119
- git: runGit,
120
- out: (line = "") => console.log(line),
121
- note: (line = "") => console.error(line),
122
- cwd: process.cwd(),
123
- self: { node: process.execPath, script: fileURLToPath(import.meta.url) },
124
- readSecret: () => readSecret(`Paste your key for ${environment.name} (it will not be shown): `),
125
- ask: readLine,
126
- openUrl,
127
- sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
128
- now: Date.now,
129
- };
145
+ const ctx = context(environment);
130
146
 
131
- // Git calls this many times and reads the answer: nothing else may be printed.
132
147
  if (command === "git-credential") {
133
148
  return commands.gitCredential(ctx, rest[0] ?? "", await readAll());
134
149
  }
@@ -176,6 +191,8 @@ async function main() {
176
191
  microsoft: values.microsoft,
177
192
  json: values.json,
178
193
  });
194
+ case "media":
195
+ return commands.media(ctx, rest[0], rest.slice(1), { site: values.site, json: values.json });
179
196
  case "link":
180
197
  return commands.link(ctx);
181
198
  // A site's build runs this and reads the one line it prints.
@@ -186,10 +203,58 @@ async function main() {
186
203
  }
187
204
  }
188
205
 
206
+ /**
207
+ * Everything a command needs.
208
+ * @param {import("../src/cli/environments.mjs").CliEnvironment} environment
209
+ * @returns {commands.Context}
210
+ */
211
+ function context(environment) {
212
+ return {
213
+ environment,
214
+ keys: defaultKeyStore(),
215
+ api: (key) => createApi({ base: environment.api, key }),
216
+ git: runGit,
217
+ out: (line = "") => console.log(line),
218
+ note: (line = "") => console.error(line),
219
+ cwd: process.cwd(),
220
+ self: { node: process.execPath, script: fileURLToPath(import.meta.url) },
221
+ readSecret: () => readSecret(`Paste your key for ${environment.name} (it will not be shown): `),
222
+ ask: readLine,
223
+ openUrl,
224
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
225
+ now: Date.now,
226
+ };
227
+ }
228
+
229
+ /**
230
+ * `sites [--env <name>] crm|site …`: the group, the environment, and the rest
231
+ * as typed. Null for every other command.
232
+ * @param {string[]} typed
233
+ */
234
+ function toolInvocation(typed) {
235
+ /** @type {string | undefined} */
236
+ let env;
237
+ let json = false;
238
+ let help = false;
239
+ /** @type {string[]} */
240
+ const rest = [];
241
+ for (let index = 0; index < typed.length; index++) {
242
+ const word = /** @type {string} */ (typed[index]);
243
+ if (word === "--env") env = typed[++index];
244
+ else if (word.startsWith("--env=")) env = word.slice(6);
245
+ else if (word === "--json") json = true;
246
+ else if (word === "--help" || word === "-h") help = true;
247
+ else rest.push(word);
248
+ }
249
+ const [group, ...after] = rest;
250
+ if (!group || !Object.hasOwn(GROUPS, group)) return null;
251
+ return { group, rest: after, env, json, help };
252
+ }
253
+
189
254
  class UsageError extends Error {}
190
255
 
191
256
  /** The commands that can be told their site with `--site` as well as after the command. */
192
- const TAKES_SITE = new Set(["tables", "rows", "data-token"]);
257
+ const TAKES_SITE = new Set(["tables", "rows", "media", "data-token"]);
193
258
 
194
259
  /** @param {string} value @param {string} flag */
195
260
  function positiveNumber(value, flag) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superintern/sites",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Make a website for a business on SuperIntern, see how it is doing, and put it online.",
5
5
  "keywords": [
6
6
  "superintern",
@@ -24,9 +24,13 @@
24
24
  "src/cli/environments.mjs",
25
25
  "src/cli/git.mjs",
26
26
  "src/cli/keys.mjs",
27
+ "src/cli/mcp-tools.json",
28
+ "src/cli/mcp.mjs",
29
+ "src/cli/media.mjs",
27
30
  "src/cli/names.mjs",
28
31
  "src/cli/package-info.mjs",
29
- "src/cli/prompt.mjs"
32
+ "src/cli/prompt.mjs",
33
+ "src/cli/tools.mjs"
30
34
  ],
31
35
  "engines": {
32
36
  "node": ">=22.12"
package/src/cli/api.mjs CHANGED
@@ -1,7 +1,15 @@
1
- // The site API, as the `sites` command uses it.
1
+ // The service, as the `sites` command uses it.
2
2
  //
3
- // Every address and shape the command relies on is in this one file, and
4
- // follows the service's own description of its API. Change them here.
3
+ // Websites are read and changed through SuperIntern's MCP server (mcp.mjs),
4
+ // the same tools Claude is given, so the command and the server can never
5
+ // offer different things. Three calls have no tool and stay on the site API
6
+ // (`/sites/v1`): whose key this is (`me`), and the pass a site's build uses to
7
+ // read what the business made public in its CRM (`dataPass`, `data`).
8
+ //
9
+ // Every address and shape the command relies on is in this file and mcp.mjs.
10
+ // Change them here.
11
+
12
+ import { createMcp } from "./mcp.mjs";
5
13
 
6
14
  export class ApiError extends Error {
7
15
  /**
@@ -15,6 +23,8 @@ export class ApiError extends Error {
15
23
  /** What code branches on. */
16
24
  this.code = detail.code;
17
25
  this.body = detail.body;
26
+ /** @type {string | undefined} the MCP tool whose own refusal this is */
27
+ this.tool = undefined;
18
28
  }
19
29
  }
20
30
 
@@ -176,6 +186,10 @@ async function send(doFetch, url, { method, bearer, json }) {
176
186
  * @param {{ base: string, key: string, fetch?: typeof fetch }} options
177
187
  */
178
188
  export function createApi({ base, key, fetch: doFetch = fetch }) {
189
+ const mcp = createMcp({ base, key, fetch: doFetch });
190
+ /** `site_read`'s whole answer. @param {string} site its slug or id */
191
+ const readSite = async (site) => (await mcp.call("site_read", { site })).data ?? {};
192
+
179
193
  /**
180
194
  * A website key (scope sites.read or sites.write). The same key is the git address's password.
181
195
  * @param {string} method @param {string} path @param {unknown} [json]
@@ -187,6 +201,9 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
187
201
  const dataBase = `${base}/sites/v1/data`;
188
202
 
189
203
  return {
204
+ /** Every tool of SuperIntern's MCP server this key may use, and a way to run one. */
205
+ mcp,
206
+
190
207
  /**
191
208
  * Whose key this is, which agents it works on, and whether it may change
192
209
  * anything (`can_write`) or only read.
@@ -198,13 +215,11 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
198
215
  },
199
216
 
200
217
  /**
201
- * Sites the key may see. A key names its own agent, so none is needed.
202
- * @param {{ agentId?: string }} [options]
218
+ * The business's sites (`site_list`). A key names its own agent.
203
219
  * @returns {Promise<Site[]>}
204
220
  */
205
- async listSites(options = {}) {
206
- const query = options.agentId ? `?agent_id=${encodeURIComponent(options.agentId)}` : "";
207
- return (await call("GET", `/sites${query}`)).sites ?? [];
221
+ async listSites() {
222
+ return (await mcp.call("site_list")).data?.sites ?? [];
208
223
  },
209
224
 
210
225
  /**
@@ -213,104 +228,134 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
213
228
  * @returns {Promise<Site | null>}
214
229
  */
215
230
  async findSite(slug) {
216
- const sites = (await call("GET", `/sites?slug=${encodeURIComponent(slug)}`)).sites ?? [];
217
- // Never trust the filter alone: a server that ignores it returns every site.
218
- return sites.find((/** @type {Site} */ site) => site.slug === slug) ?? null;
231
+ try {
232
+ const site = (await readSite(slug)).site;
233
+ // Never trust the lookup alone: `site_read` also takes an id.
234
+ return site?.slug === slug ? site : null;
235
+ } catch (error) {
236
+ // The tool found no such site. A server that is not there at all is not that.
237
+ if (error instanceof ApiError && error.code === "not_found" && error.tool) return null;
238
+ throw error;
239
+ }
219
240
  },
220
241
 
221
242
  /**
222
- * The site belongs to the key's own business: no agent is named.
243
+ * The site belongs to the key's own business (`site_create`).
223
244
  * @param {{ slug: string, name?: string }} input
224
245
  * @returns {Promise<Site>}
225
246
  */
226
247
  async createSite(input) {
227
- return (await call("POST", "/sites", { slug: input.slug, name: input.name })).site;
248
+ return (await mcp.call("site_create", { slug: input.slug, name: input.name ?? input.slug })).data.site;
228
249
  },
229
250
 
230
251
  /**
231
252
  * Finish making a site's repository, for a site whose `git.ready` is
232
- * false. Refusals: `repository_in_progress` (wait), `repository_failed`
233
- * (try again), `repository_unavailable`.
253
+ * false: asking for git access to push does it (`site_git_access`).
254
+ * Refusals: `repository_in_progress` (wait), `repository_failed` (try
255
+ * again), `repository_unavailable`.
234
256
  * @param {string} id @returns {Promise<Site>}
235
257
  */
236
258
  async prepareRepository(id) {
237
- return (await call("POST", `/sites/${encodeURIComponent(id)}/repository`)).site;
259
+ await mcp.call("site_git_access", { site: id, access: "write" });
260
+ return (await readSite(id)).site;
238
261
  },
239
262
 
240
263
  /** @param {string} id @returns {Promise<Site>} */
241
264
  async getSite(id) {
242
- return (await call("GET", `/sites/${encodeURIComponent(id)}`)).site;
265
+ return (await readSite(id)).site;
243
266
  },
244
267
 
245
268
  /**
246
- * Newest first.
247
- * @param {string} id @param {{ limit?: number }} [options]
248
- * @returns {Promise<Version[]>}
269
+ * The site with its latest versions and builds, newest first
270
+ * (`site_read`: the latest few of each).
271
+ * @param {string} id @param {{ wait?: boolean }} [options]
272
+ * @returns {Promise<{ site: Site, versions: Version[], builds: Build[] }>}
249
273
  */
250
- async versions(id, options = {}) {
251
- return (await call("GET", `/sites/${encodeURIComponent(id)}/versions?limit=${options.limit ?? 20}`)).versions ?? [];
274
+ async readSite(id, options = {}) {
275
+ // wait_for_build: the server holds the answer (up to 90 s) until the newest push's build ends, and always lists that build.
276
+ const data = options.wait ? ((await mcp.call("site_read", { site: id, wait_for_build: true })).data ?? {}) : await readSite(id);
277
+ return { site: data.site, versions: Array.isArray(data.versions) ? data.versions : [], builds: Array.isArray(data.builds) ? data.builds : [] };
252
278
  },
253
279
 
254
280
  /**
255
- * Newest first; null when the service has no build information.
256
- * @param {string} id @param {{ limit?: number }} [options]
257
- * @returns {Promise<Build[] | null>}
258
- */
259
- async builds(id, options = {}) {
260
- try {
261
- return (await call("GET", `/sites/${encodeURIComponent(id)}/builds?limit=${options.limit ?? 10}`)).builds ?? [];
262
- } catch (error) {
263
- // The site was found a moment ago, so "not found" here is the route.
264
- if (error instanceof ApiError && error.status === 404) return null;
265
- throw error;
266
- }
267
- },
268
-
269
- /**
270
- * Serve a version; the newest ready one when none is named.
271
- * Needs a key that may change sites.
272
- * @param {string} id @param {string} [versionId]
281
+ * Serve a version (`site_publish`): the newest ready one when no number
282
+ * is given. Needs a key that may change sites.
283
+ * @param {string} id @param {number} [number] the version's number, as `site_read` shows it
273
284
  * @returns {Promise<Site>}
274
285
  */
275
- async publish(id, versionId) {
276
- return (await call("POST", `/sites/${encodeURIComponent(id)}/publish`, versionId ? { version_id: versionId } : {})).site;
286
+ async publish(id, number) {
287
+ return (await mcp.call("site_publish", number === undefined ? { site: id } : { site: id, version: number })).data.site;
277
288
  },
278
289
 
279
290
  /** @param {string} id @returns {Promise<Site>} */
280
291
  async unpublish(id) {
281
- return (await call("POST", `/sites/${encodeURIComponent(id)}/unpublish`, {})).site;
292
+ return (await mcp.call("site_unpublish", { site: id })).data.site;
282
293
  },
283
294
 
284
295
  /**
285
- * Remove a site for good. The service asks for its slug again, as the
286
- * person typed it, so an id from the wrong place removes nothing.
287
- * Needs a key that may change sites.
296
+ * Remove a site for good (`site_remove`). The service asks for its slug
297
+ * again, as the person typed it, so an id from the wrong place removes
298
+ * nothing. Needs a key that may change sites.
288
299
  * @param {string} id @param {string} slug
289
300
  * @returns {Promise<RemovedSite>}
290
301
  */
291
302
  async removeSite(id, slug) {
292
- return (await call("POST", `/sites/${encodeURIComponent(id)}/remove`, { confirm: slug })).site;
303
+ return (await mcp.call("site_remove", { site: id, confirm: slug })).data.site;
293
304
  },
294
305
 
295
306
  /**
296
307
  * Whether customers may sign in to the site, and how: `{enabled,
297
- * passwords, providers: {google: {enabled, available}, microsoft: …}}`.
298
- * A key that may only look is enough.
308
+ * passwords, providers: {google: {enabled, available}, microsoft: …}}`,
309
+ * from `site_read`. A key that may only look is enough.
299
310
  * @param {string} id @returns {Promise<SignInSwitches>}
300
311
  */
301
312
  async signInSwitches(id) {
302
- return call("GET", `/sites/${encodeURIComponent(id)}/customers/sign-in`);
313
+ const data = await readSite(id);
314
+ if (data.customer_accounts && typeof data.customer_accounts === "object") return data.customer_accounts;
315
+ throw new ApiError("This service doesn't show customer accounts to a key yet.", { status: 404, code: "no_customer_accounts" });
303
316
  },
304
317
 
305
318
  /**
306
- * Switch customer sign-in: only what is sent changes (`enabled`,
307
- * `passwords`, `google`, `microsoft`, each true or false). Needs a key that
308
- * may change sites.
319
+ * Switch customer sign-in (`site_update`'s `customer_accounts`): only what
320
+ * is sent changes (`enabled`, `passwords`, `google`, `microsoft`, each
321
+ * true or false). Needs a key that may change sites.
309
322
  * @param {string} id @param {Partial<Record<"enabled" | "passwords" | "google" | "microsoft", boolean>>} changes
310
323
  * @returns {Promise<SignInSwitches>}
311
324
  */
312
325
  async switchSignIn(id, changes) {
313
- return call("POST", `/sites/${encodeURIComponent(id)}/customers/sign-in`, changes);
326
+ return (await mcp.call("site_update", { site: id, customer_accounts: changes })).data.customer_accounts;
327
+ },
328
+
329
+ /**
330
+ * The site's media files, whether it may have them here (`available`),
331
+ * and how much room they take (`usage`) (`site_media_list`). A key that
332
+ * may only look is enough.
333
+ * @param {string} id @returns {Promise<MediaList>}
334
+ */
335
+ async mediaFiles(id) {
336
+ const data = (await mcp.call("site_media_list", { site: id })).data;
337
+ return { available: data?.available !== false, files: Array.isArray(data?.files) ? data.files : [], usage: data?.usage ?? {} };
338
+ },
339
+
340
+ /**
341
+ * Ask for an address to send one media file to (`site_media_upload`): its
342
+ * name on this computer (the service makes the name it is kept under) and
343
+ * its exact size in bytes. Needs a key that may change sites.
344
+ * @param {string} id @param {{ name: string, size: number }} file
345
+ * @returns {Promise<MediaUpload>}
346
+ */
347
+ async startMediaUpload(id, file) {
348
+ return (await mcp.call("site_media_upload", { site: id, name: file.name, size: file.size })).data;
349
+ },
350
+
351
+ /**
352
+ * Stop serving one media file and delete it (`site_media_delete`). Needs
353
+ * a key that may change sites.
354
+ * @param {string} id @param {string} name
355
+ */
356
+ async deleteMedia(id, name) {
357
+ if (!pathWord(name)) throw new Error("That is not a media file's name, so nothing was deleted.");
358
+ return (await mcp.call("site_media_delete", { site: id, name })).data;
314
359
  },
315
360
 
316
361
  /**
@@ -374,4 +419,30 @@ export function createApi({ base, key, fetch: doFetch = fetch }) {
374
419
  * @property {Record<string, { enabled?: boolean, available?: boolean }>} [providers] Google and Microsoft
375
420
  */
376
421
 
422
+ /**
423
+ * One media file of a site.
424
+ * @typedef {object} MediaFile
425
+ * @property {string} name what it is kept under, such as `summer-menu.pdf`
426
+ * @property {string} path `/_media/<name>`
427
+ * @property {number} size
428
+ * @property {string} [content_type]
429
+ * @property {string} [state]
430
+ * @property {string | null} [ready_at]
431
+ */
432
+
433
+ /**
434
+ * @typedef {object} MediaList
435
+ * @property {boolean} available false where sites may not keep media files yet
436
+ * @property {MediaFile[]} files
437
+ * @property {{ files?: number, bytes?: number, max_files?: number, max_bytes?: number, max_file_bytes?: number }} usage
438
+ */
439
+
440
+ /**
441
+ * Where and how to send one media file: the file as it will be listed, and
442
+ * an address on the site's free address that takes it for an hour.
443
+ * @typedef {object} MediaUpload
444
+ * @property {MediaFile} media
445
+ * @property {{ url: string, method?: string, headers?: Record<string, string>, expires_at?: string }} upload
446
+ */
447
+
377
448
  /** @typedef {ReturnType<typeof createApi>} Api */