@zaisma/cli 0.10.0 → 0.12.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 (2) hide show
  1. package/package.json +1 -1
  2. package/zaisma.mjs +21 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zaisma/cli",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Upload and publish browser games on Zaisma from the command line.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://zaisma.com",
package/zaisma.mjs CHANGED
@@ -3,12 +3,14 @@
3
3
  // Docs: https://github.com/zaisma/zaisma/blob/main/docs/DEVELOPER-API.md#the-upload-command
4
4
 
5
5
  import { createHash } from "node:crypto";
6
- import { createReadStream } from "node:fs";
6
+ import { createReadStream, readFileSync } from "node:fs";
7
7
  import { open, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
8
8
  import { extname, join, relative, sep } from "node:path";
9
9
 
10
10
  const API = (process.env.ZAISMA_API || "https://zaisma.com").replace(/\/+$/, "");
11
11
  const KEY = process.env.ZAISMA_KEY || "";
12
+ /** This command's version, sent as its user agent so a game's history can say "the upload command 0.10.0". */
13
+ const CLI_VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
12
14
  /** Files bigger than this go in parts; the server says how big each part is. */
13
15
  const DIRECT_BYTES = 95 * 1024 * 1024;
14
16
  const JUNK = new Set([".DS_Store", "Thumbs.db", "desktop.ini", "__MACOSX", ".git", "node_modules"]);
@@ -88,6 +90,11 @@ const COMMANDS = {
88
90
  arguments: [{ name: "slug" }, { name: "hosts", isRest: true, isOptional: true }],
89
91
  flags: { none: { hasValue: false, about: "Set the list to none: the game server calls no other servers" } },
90
92
  },
93
+ "own-servers": {
94
+ about: "Your own servers the game connects to from players' browsers, like wss://play.example.com, named in the game's menu; given addresses, set the whole list",
95
+ arguments: [{ name: "slug" }, { name: "urls", isRest: true, isOptional: true }],
96
+ flags: { none: { hasValue: false, about: "Set the list to none: the game uses no servers of its own" } },
97
+ },
91
98
  links: { about: "A game's registered links, which it opens with Zaisma.links.open: each name, address and who it opens for", arguments: [{ name: "slug" }], flags: {} },
92
99
  "links set": {
93
100
  about: "Add a link, or change the one with the same name",
@@ -353,7 +360,7 @@ async function api(method, path, body) {
353
360
  try {
354
361
  response = await fetch(`${API}/api/dev${path}`, {
355
362
  method,
356
- headers: { authorization: `Bearer ${KEY}`, "x-zaisma-client": "cli", ...(body && !(body instanceof Uint8Array) ? { "content-type": "application/json" } : {}) },
363
+ headers: { authorization: `Bearer ${KEY}`, "x-zaisma-client": "cli", "user-agent": `zaisma-cli/${CLI_VERSION}`, ...(body && !(body instanceof Uint8Array) ? { "content-type": "application/json" } : {}) },
357
364
  body: body instanceof Uint8Array ? body : body ? JSON.stringify(body) : undefined,
358
365
  });
359
366
  } catch (error) {
@@ -865,6 +872,17 @@ async function allowedHosts(values, flags) {
865
872
  if (given.length || flags.none) console.log("It works within a minute.");
866
873
  }
867
874
 
875
+ /** The game's own servers players' browsers connect to (own_server_urls on the game), as the MCP's get_game and update_game. */
876
+ async function ownServers(values, flags) {
877
+ const given = (values.urls ?? "").split(/[\s,]+/).filter(Boolean);
878
+ if (given.length && flags.none) refuse("unknown_field", { message: "Addresses and --none were both given.", field: "--none", fix: `Give the whole list, like zaisma own-servers ${values.slug} wss://play.example.com, or --none for none.` });
879
+ const answer = given.length || flags.none ? await api("PATCH", `/games/${values.slug}`, { own_server_urls: given }) : await api("GET", `/games/${values.slug}`);
880
+ if (isJson) return printJson(answer);
881
+ const servers = answer.game.own_server_urls;
882
+ console.log(servers.length ? `${values.slug} connects to its own servers: ${servers.join(", ")}` : `${values.slug} uses no servers of its own. Add one with: zaisma own-servers ${values.slug} wss://play.example.com`);
883
+ if (given.length || flags.none) console.log(servers.length ? "Live now: the game's menu names them." : "Live now.");
884
+ }
885
+
868
886
  /** Who a link opens for, in words (who_can_open). */
869
887
  const LINK_AUDIENCE_WORDS = { everyone: "opens for everyone", signed_in_adults: "opens for signed-in adults", nobody: "opens for nobody" };
870
888
 
@@ -1099,6 +1117,7 @@ async function run({ command, values, flags, globalFlags, rest }) {
1099
1117
  return EXIT_CODES.done;
1100
1118
  }
1101
1119
  if (command === "allowed-hosts") await allowedHosts(values, flags);
1120
+ else if (command === "own-servers") await ownServers(values, flags);
1102
1121
  else if (command === "links" || command.startsWith("links ")) await links(command, values, flags);
1103
1122
  else if (command === "secrets" || command.startsWith("secrets ")) await secrets(command, values);
1104
1123
  else if (command === "database" || command.startsWith("database ")) await database(command, values, flags);