{"draft":null,"from":2,"to":318,"files":[{"path":"client/src/visitor.ts","added":44,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/visitor.ts\n@@ -0,0 +1,44 @@\n+// A visitor folder: abso join <project> --reader with no sign-in, for a public project. It reads the\n+// project through the routes anyone can read, and sends no credential, whatever the environment holds\n+// (config.ts reads no token for it, and Api sends none and follows no redirect). Which commands it runs\n+// is a list of reads: anything not on it is refused here, before any call, so a new command stays\n+// refused until someone adds it. The server refuses writes from it too; this is so the refusal is plain.\n+\n+import { type Parsed, UsageError } from \"./args.ts\";\n+\n+/** The commands a visitor folder runs, each with the flags it takes there. */\n+export const VISITOR_READS: Readonly<Record<string, readonly string[]>> = {\n+\tstatus: [],\n+\tlog: [\"limit\", \"before\", \"draft\", \"since\", \"by\", \"count\"],\n+\tshow: [\"draft\"],\n+\tfiles: [\"draft\", \"version\"],\n+\tblame: [\"from\", \"to\", \"version\", \"draft\"],\n+\twhy: [\"draft\"],\n+\twhere: [],\n+\tissues: [\"open\", \"status\", \"agent\", \"parent\", \"label\", \"labels\"],\n+\tissue: [],\n+\tsearch: [\"limit\"],\n+};\n+\n+/** Commands about this box, not the folder: they work from anywhere, a visitor folder too. */\n+export const VISITOR_ELSEWHERE: readonly string[] = [\"login\", \"logout\"];\n+\n+/** Flags every command takes (--server is checked against the folder's own server before this, in main.ts). */\n+const EVERY = new Set([\"json\", \"help\", \"server\"]);\n+\n+export function visitorRefusal(project: string): string {\n+\treturn `This folder reads ${project} signed out. To work on it: abso login, then abso join ${project} in a new folder.`;\n+}\n+\n+/** Refuses, before any call, a command or a flag a visitor folder doesn't run. */\n+export function checkVisitor(command: string, args: Parsed, project: string): void {\n+\tif (VISITOR_ELSEWHERE.includes(command)) return;\n+\tconst flags = VISITOR_READS[command];\n+\tif (flags === undefined) throw new UsageError(visitorRefusal(project));\n+\tfor (const name of args.flags.keys())\n+\t\tif (!EVERY.has(name) && !flags.includes(name))\n+\t\t\tthrow new UsageError(`${visitorRefusal(project)} Here, ${command} reads only; --${name} isn't one of its reads.`);\n+\t// abso issue new and abso issue draft write: here, issue takes only a number.\n+\tif (command === \"issue\" && !(args.positionals.length === 1 && /^#?\\d+$/.test(args.positionals[0]!)))\n+\t\tthrow new UsageError(`${visitorRefusal(project)} Here, issue reads one issue: abso issue <N>.`);\n+}"}],"unmatched":[]}