{"file":"client/src/orgs.ts","version":318,"total":186,"from":1,"to":186,"lines":[{"n":1,"text":"// Organizations from the CLI: abso orgs and abso org <name>. They read as the","atom":"a288","author":"pinch","version":34},{"n":2,"text":"// person who approved this box's sign-in (abso login). abso org new makes one, and","atom":"a2074","author":"box-grants","version":185},{"n":3,"text":"// abso init --org makes a project in one, from a box approved for all its","atom":"a2074","author":"box-grants","version":185},{"n":4,"text":"// person's projects (abso 663). Changing an org (invite, role, remove, leave,","atom":"a2074","author":"box-grants","version":185},{"n":5,"text":"// settings) stays on the website: a box sits where agents run, so the server takes","atom":"a2074","author":"box-grants","version":185},{"n":6,"text":"// no other org change from it.","atom":"a2074","author":"box-grants","version":185},{"n":7,"text":"","atom":"a288","author":"pinch","version":34},{"n":8,"text":"import { type Parsed, str, UsageError } from \"./args.ts\";","atom":"a2074","author":"box-grants","version":185},{"n":9,"text":"import { type Answer, boxCreateOrg, boxGet, originOf, readBox } from \"./box.ts\";","atom":"a2074","author":"box-grants","version":185},{"n":10,"text":"import type { Output } from \"./commands.ts\";","atom":"a292","author":"pinch","version":34},{"n":11,"text":"","atom":"a288","author":"pinch","version":34},{"n":12,"text":"/** The website for an API server: api.<site> serves <site>; any other server serves its own pages. */","atom":"a288","author":"pinch","version":34},{"n":13,"text":"export function siteOf(server: string): string {","atom":"a288","author":"pinch","version":34},{"n":14,"text":"\ttry {","atom":"a288","author":"pinch","version":34},{"n":15,"text":"\t\tconst url = new URL(server);","atom":"a288","author":"pinch","version":34},{"n":16,"text":"\t\tif (url.hostname.startsWith(\"api.\")) url.hostname = url.hostname.slice(\"api.\".length);","atom":"a288","author":"pinch","version":34},{"n":17,"text":"\t\treturn url.origin;","atom":"a288","author":"pinch","version":34},{"n":18,"text":"\t} catch {","atom":"a288","author":"pinch","version":34},{"n":19,"text":"\t\treturn server;","atom":"a288","author":"pinch","version":34},{"n":20,"text":"\t}","atom":"a288","author":"pinch","version":34},{"n":21,"text":"}","atom":"a288","author":"pinch","version":34},{"n":22,"text":"","atom":"a288","author":"pinch","version":34},{"n":23,"text":"/** The flags that change an org, in the order Design wrote them; each names where the website does it. */","atom":"a288","author":"pinch","version":34},{"n":24,"text":"const CHANGES: readonly { flag: string; tab: string }[] = [","atom":"a288","author":"pinch","version":34},{"n":25,"text":"\t{ flag: \"invite\", tab: \"People\" },","atom":"a288","author":"pinch","version":34},{"n":26,"text":"\t{ flag: \"role\", tab: \"People\" },","atom":"a288","author":"pinch","version":34},{"n":27,"text":"\t{ flag: \"remove\", tab: \"People\" },","atom":"a288","author":"pinch","version":34},{"n":28,"text":"\t{ flag: \"leave\", tab: \"People\" },","atom":"a288","author":"pinch","version":34},{"n":29,"text":"\t{ flag: \"members\", tab: \"Settings\" },","atom":"a288","author":"pinch","version":34},{"n":30,"text":"\t{ flag: \"projects-by\", tab: \"Settings\" },","atom":"a288","author":"pinch","version":34},{"n":31,"text":"];","atom":"a288","author":"pinch","version":34},{"n":32,"text":"","atom":"a288","author":"pinch","version":34},{"n":33,"text":"const WEBSITE_ONLY =","atom":"a288","author":"pinch","version":34},{"n":34,"text":"\t\"Organizations are changed on the website; from the CLI they can be read, and made with abso org new, as the person who approved this box's sign-in\";","atom":"a2074","author":"box-grants","version":185},{"n":35,"text":"","atom":"a288","author":"pinch","version":34},{"n":36,"text":"/** Where the box's sign-in is read from and how the server is reached; tests pass their own. */","atom":"a292","author":"pinch","version":34},{"n":37,"text":"export interface OrgIo {","atom":"a292","author":"pinch","version":34},{"n":38,"text":"\treadonly home?: string;","atom":"a292","author":"pinch","version":34},{"n":39,"text":"\treadonly fetch?: typeof fetch;","atom":"a292","author":"pinch","version":34},{"n":40,"text":"}","atom":"a292","author":"pinch","version":34},{"n":41,"text":"","atom":"a292","author":"pinch","version":34},{"n":42,"text":"async function read(server: string, path: string, io: OrgIo): Promise<Answer> {","atom":"a292","author":"pinch","version":34},{"n":43,"text":"\tconst record = io.home === undefined ? readBox(server) : readBox(server, io.home);","atom":"a292","author":"pinch","version":34},{"n":44,"text":"\tif (!record)","atom":"a288","author":"pinch","version":34},{"n":45,"text":"\t\tthrow new UsageError(","atom":"a288","author":"pinch","version":34},{"n":46,"text":"\t\t\t`this box isn't signed in to ${originOf(server)}. abso login signs it in; org reads answer as the person who approves it`,","atom":"a288","author":"pinch","version":34},{"n":47,"text":"\t\t);","atom":"a288","author":"pinch","version":34},{"n":48,"text":"\treturn boxGet(record, path, io.fetch);","atom":"a292","author":"pinch","version":34},{"n":49,"text":"}","atom":"a288","author":"pinch","version":34},{"n":50,"text":"","atom":"a288","author":"pinch","version":34},{"n":51,"text":"/** What a refusal from an org read means, in words. */","atom":"a288","author":"pinch","version":34},{"n":52,"text":"function refused(a: Answer, what: string, server: string): UsageError {","atom":"a288","author":"pinch","version":34},{"n":53,"text":"\tconst said = typeof a.body.error === \"string\" ? a.body.error : `status ${a.status}`;","atom":"a288","author":"pinch","version":34},{"n":54,"text":"\tif (a.status === 401)","atom":"a292","author":"pinch","version":34},{"n":55,"text":"\t\treturn new UsageError(`${originOf(server)} didn't take this box's sign-in (${said}). abso login renews it`);","atom":"a292","author":"pinch","version":34},{"n":56,"text":"\tif (a.status === 404 && /aren't on here/.test(said)) return new UsageError(`${originOf(server)}: ${said}`);","atom":"a288","author":"pinch","version":34},{"n":57,"text":"\tif (a.status === 404) return new UsageError(`${what}: ${said}`);","atom":"a288","author":"pinch","version":34},{"n":58,"text":"\treturn new UsageError(`${originOf(server)} refused ${what} (${a.status}): ${said}`);","atom":"a288","author":"pinch","version":34},{"n":59,"text":"}","atom":"a288","author":"pinch","version":34},{"n":60,"text":"","atom":"a288","author":"pinch","version":34},{"n":61,"text":"const when = (iso: unknown) => (typeof iso === \"string\" ? `${iso.slice(0, 16).replace(\"T\", \" \")} UTC` : \"?\");","atom":"a288","author":"pinch","version":34},{"n":62,"text":"","atom":"a288","author":"pinch","version":34},{"n":63,"text":"interface OrgRow {","atom":"a288","author":"pinch","version":34},{"n":64,"text":"\tname: string;","atom":"a288","author":"pinch","version":34},{"n":65,"text":"\tdisplayName: string;","atom":"a288","author":"pinch","version":34},{"n":66,"text":"\trole: string;","atom":"a288","author":"pinch","version":34},{"n":67,"text":"}","atom":"a288","author":"pinch","version":34},{"n":68,"text":"interface Invitation {","atom":"a288","author":"pinch","version":34},{"n":69,"text":"\tid: string;","atom":"a288","author":"pinch","version":34},{"n":70,"text":"\torg: string;","atom":"a288","author":"pinch","version":34},{"n":71,"text":"\trole: string;","atom":"a288","author":"pinch","version":34},{"n":72,"text":"\texpiresAt: string;","atom":"a288","author":"pinch","version":34},{"n":73,"text":"}","atom":"a288","author":"pinch","version":34},{"n":74,"text":"","atom":"a288","author":"pinch","version":34},{"n":75,"text":"/** abso orgs: your organizations, your role in each, and invitations waiting for you. */","atom":"a288","author":"pinch","version":34},{"n":76,"text":"export async function runOrgs(server: string, io: OrgIo = {}): Promise<Output> {","atom":"a292","author":"pinch","version":34},{"n":77,"text":"\tconst a = await read(server, \"/orgs\", io);","atom":"a292","author":"pinch","version":34},{"n":78,"text":"\tif (a.status !== 200) throw refused(a, \"the list of your organizations\", server);","atom":"a288","author":"pinch","version":34},{"n":79,"text":"\tconst orgs = (a.body.orgs ?? []) as OrgRow[];","atom":"a288","author":"pinch","version":34},{"n":80,"text":"\tconst invitations = (a.body.invitations ?? []) as Invitation[];","atom":"a288","author":"pinch","version":34},{"n":81,"text":"\tconst lines =","atom":"a288","author":"pinch","version":34},{"n":82,"text":"\t\torgs.length === 0","atom":"a288","author":"pinch","version":34},{"n":83,"text":"\t\t\t? [\"You're in no organizations.\"]","atom":"a288","author":"pinch","version":34},{"n":84,"text":"\t\t\t: [","atom":"a288","author":"pinch","version":34},{"n":85,"text":"\t\t\t\t\t`Your organizations (${orgs.length}):`,","atom":"a288","author":"pinch","version":34},{"n":86,"text":"\t\t\t\t\t...orgs.map(","atom":"a292","author":"pinch","version":34},{"n":87,"text":"\t\t\t\t\t\t(o) => `  ${o.name}${o.displayName && o.displayName !== o.name ? ` (${o.displayName})` : \"\"}: ${o.role}`,","atom":"a292","author":"pinch","version":34},{"n":88,"text":"\t\t\t\t\t),","atom":"a292","author":"pinch","version":34},{"n":89,"text":"\t\t\t\t];","atom":"a288","author":"pinch","version":34},{"n":90,"text":"\tif (invitations.length > 0)","atom":"a288","author":"pinch","version":34},{"n":91,"text":"\t\tlines.push(","atom":"a288","author":"pinch","version":34},{"n":92,"text":"\t\t\t\"Invited to:\",","atom":"a288","author":"pinch","version":34},{"n":93,"text":"\t\t\t...invitations.map((i) => `  ${i.org} as ${i.role}, until ${when(i.expiresAt)}`),","atom":"a288","author":"pinch","version":34},{"n":94,"text":"\t\t\t`Accept them on the website, signed in: ${siteOf(server)}.`,","atom":"a292","author":"pinch","version":34},{"n":95,"text":"\t\t);","atom":"a288","author":"pinch","version":34},{"n":96,"text":"\treturn { text: lines.join(\"\\n\"), json: { orgs, invitations } };","atom":"a288","author":"pinch","version":34},{"n":97,"text":"}","atom":"a288","author":"pinch","version":34},{"n":98,"text":"","atom":"a288","author":"pinch","version":34},{"n":99,"text":"interface Member {","atom":"a288","author":"pinch","version":34},{"n":100,"text":"\tid: string;","atom":"a288","author":"pinch","version":34},{"n":101,"text":"\trole: string;","atom":"a288","author":"pinch","version":34},{"n":102,"text":"\tname: string | null;","atom":"a288","author":"pinch","version":34},{"n":103,"text":"\traised?: { project: string; role: string }[];","atom":"a288","author":"pinch","version":34},{"n":104,"text":"}","atom":"a288","author":"pinch","version":34},{"n":105,"text":"interface Invite {","atom":"a288","author":"pinch","version":34},{"n":106,"text":"\tid: string;","atom":"a288","author":"pinch","version":34},{"n":107,"text":"\trole: string;","atom":"a288","author":"pinch","version":34},{"n":108,"text":"\tkind: \"link\" | \"person\";","atom":"a288","author":"pinch","version":34},{"n":109,"text":"\texpiresAt: string;","atom":"a288","author":"pinch","version":34},{"n":110,"text":"}","atom":"a288","author":"pinch","version":34},{"n":111,"text":"","atom":"a288","author":"pinch","version":34},{"n":112,"text":"/** abso org <name>, abso org new <name>, and the change flags, which say where the website does each. */","atom":"a288","author":"pinch","version":34},{"n":113,"text":"export async function runOrg(args: Parsed, server: string, io: OrgIo = {}): Promise<Output> {","atom":"a292","author":"pinch","version":34},{"n":114,"text":"\tconst [first, second, ...more] = args.positionals;","atom":"a288","author":"pinch","version":34},{"n":115,"text":"\tconst asked = CHANGES.filter((c) => args.flags.has(c.flag));","atom":"a292","author":"pinch","version":34},{"n":116,"text":"\tif (first === \"new\") {","atom":"a288","author":"pinch","version":34},{"n":117,"text":"\t\tif (second === undefined || more.length > 0) throw new UsageError('abso org new <name> [--name \"<shown name>\"]');","atom":"a288","author":"pinch","version":34},{"n":118,"text":"\t\tif (asked.length > 0) throw new UsageError(\"abso org new takes --name only\");","atom":"a2074","author":"box-grants","version":185},{"n":119,"text":"\t\tconst record = io.home === undefined ? readBox(server) : readBox(server, io.home);","atom":"a2074","author":"box-grants","version":185},{"n":120,"text":"\t\tif (!record)","atom":"a2074","author":"box-grants","version":185},{"n":121,"text":"\t\t\tthrow new UsageError(","atom":"a2074","author":"box-grants","version":185},{"n":122,"text":"\t\t\t\t`this box isn't signed in to ${originOf(server)}. abso login signs it in; approve all your projects to make organizations from here`,","atom":"a2074","author":"box-grants","version":185},{"n":123,"text":"\t\t\t);","atom":"a2074","author":"box-grants","version":185},{"n":124,"text":"\t\tconst made = await boxCreateOrg(record, second, str(args, \"name\"), io.fetch);","atom":"a2074","author":"box-grants","version":185},{"n":125,"text":"\t\tconst name = typeof made.name === \"string\" ? made.name : second;","atom":"a2074","author":"box-grants","version":185},{"n":126,"text":"\t\treturn {","atom":"a2074","author":"box-grants","version":185},{"n":127,"text":"\t\t\ttext: `Made the organization ${name}; you own it. Its page: ${siteOf(server)}/${name}. abso init --org ${name} --project <name> makes a project in it.`,","atom":"a2074","author":"box-grants","version":185},{"n":128,"text":"\t\t\tjson: { org: made },","atom":"a2074","author":"box-grants","version":185},{"n":129,"text":"\t\t};","atom":"a2074","author":"box-grants","version":185},{"n":130,"text":"\t}","atom":"a288","author":"pinch","version":34},{"n":131,"text":"\tif (first === undefined || second !== undefined)","atom":"a292","author":"pinch","version":34},{"n":132,"text":"\t\tthrow new UsageError(\"abso org <name> [one change], or abso org new <name>\");","atom":"a292","author":"pinch","version":34},{"n":133,"text":"\tif (args.flags.has(\"as\") && !args.flags.has(\"invite\")) throw new UsageError(\"--as goes with --invite\");","atom":"a292","author":"pinch","version":34},{"n":134,"text":"\tif (asked.length > 1)","atom":"a288","author":"pinch","version":34},{"n":135,"text":"\t\tthrow new UsageError(`one change at a time: --${asked.map((c) => c.flag).join(\" and --\")} were given together`);","atom":"a288","author":"pinch","version":34},{"n":136,"text":"\tif (asked.length === 1)","atom":"a288","author":"pinch","version":34},{"n":137,"text":"\t\tthrow new UsageError(","atom":"a292","author":"pinch","version":34},{"n":138,"text":"\t\t\t`${WEBSITE_ONLY}. --${asked[0]!.flag} is on ${first}'s ${asked[0]!.tab} tab: ${siteOf(server)}/${first}.`,","atom":"a292","author":"pinch","version":34},{"n":139,"text":"\t\t);","atom":"a292","author":"pinch","version":34},{"n":140,"text":"","atom":"a288","author":"pinch","version":34},{"n":141,"text":"\tconst a = await read(server, `/orgs/${encodeURIComponent(first)}`, io);","atom":"a292","author":"pinch","version":34},{"n":142,"text":"\tif (a.status !== 200) throw refused(a, first, server);","atom":"a288","author":"pinch","version":34},{"n":143,"text":"\tconst org = a.body as {","atom":"a288","author":"pinch","version":34},{"n":144,"text":"\t\tname: string;","atom":"a288","author":"pinch","version":34},{"n":145,"text":"\t\tdisplayName: string;","atom":"a288","author":"pinch","version":34},{"n":146,"text":"\t\tdescription: string | null;","atom":"a288","author":"pinch","version":34},{"n":147,"text":"\t\trole?: string;","atom":"a288","author":"pinch","version":34},{"n":148,"text":"\t\tmembersCan?: string;","atom":"a288","author":"pinch","version":34},{"n":149,"text":"\t\twhoMakesProjects?: string;","atom":"a288","author":"pinch","version":34},{"n":150,"text":"\t\tmembers?: Member[];","atom":"a288","author":"pinch","version":34},{"n":151,"text":"\t\tprojects?: string[];","atom":"a288","author":"pinch","version":34},{"n":152,"text":"\t\tinvites?: Invite[];","atom":"a288","author":"pinch","version":34},{"n":153,"text":"\t};","atom":"a288","author":"pinch","version":34},{"n":154,"text":"\tconst lines = [`${org.name}${org.displayName && org.displayName !== org.name ? ` (${org.displayName})` : \"\"}`];","atom":"a288","author":"pinch","version":34},{"n":155,"text":"\tif (org.description) lines.push(`  ${org.description.replace(/\\r?\\n/g, \"\\n  \")}`);","atom":"a288","author":"pinch","version":34},{"n":156,"text":"\tif (org.role === undefined) {","atom":"a288","author":"pinch","version":34},{"n":157,"text":"\t\tlines.push(\"You aren't a member, so its people and settings aren't shown.\");","atom":"a288","author":"pinch","version":34},{"n":158,"text":"\t\treturn { text: lines.join(\"\\n\"), json: { org } };","atom":"a288","author":"pinch","version":34},{"n":159,"text":"\t}","atom":"a288","author":"pinch","version":34},{"n":160,"text":"\tlines.push(","atom":"a288","author":"pinch","version":34},{"n":161,"text":"\t\t`You're ${org.role === \"owner\" ? \"an owner\" : \"a member\"}. Members can ${org.membersCan ?? \"?\"} every project; ${org.whoMakesProjects === \"owners\" ? \"only owners make\" : \"members make\"} projects.`,","atom":"a288","author":"pinch","version":34},{"n":162,"text":"\t);","atom":"a288","author":"pinch","version":34},{"n":163,"text":"\tconst projects = org.projects ?? [];","atom":"a288","author":"pinch","version":34},{"n":164,"text":"\tlines.push(projects.length === 0 ? \"Projects: none yet.\" : `Projects (${projects.length}): ${projects.join(\", \")}`);","atom":"a288","author":"pinch","version":34},{"n":165,"text":"\tconst members = org.members ?? [];","atom":"a288","author":"pinch","version":34},{"n":166,"text":"\tlines.push(`People (${members.length}):`);","atom":"a288","author":"pinch","version":34},{"n":167,"text":"\tfor (const m of members) {","atom":"a288","author":"pinch","version":34},{"n":168,"text":"\t\tconst raised = (m.raised ?? []).map((r) => `${r.role} in ${r.project}`);","atom":"a288","author":"pinch","version":34},{"n":169,"text":"\t\tlines.push(","atom":"a292","author":"pinch","version":34},{"n":170,"text":"\t\t\t`  ${m.name ?? \"(no name yet)\"}: ${m.role}${raised.length > 0 ? `, raised to ${raised.join(\", \")}` : \"\"}`,","atom":"a292","author":"pinch","version":34},{"n":171,"text":"\t\t);","atom":"a292","author":"pinch","version":34},{"n":172,"text":"\t}","atom":"a288","author":"pinch","version":34},{"n":173,"text":"\tif (org.invites !== undefined && org.invites.length > 0) {","atom":"a288","author":"pinch","version":34},{"n":174,"text":"\t\tlines.push(\"Open invites:\");","atom":"a288","author":"pinch","version":34},{"n":175,"text":"\t\tfor (const i of org.invites)","atom":"a288","author":"pinch","version":34},{"n":176,"text":"\t\t\tlines.push(`  ${i.kind === \"link\" ? \"a link\" : \"a person, by name\"}, as ${i.role}, until ${when(i.expiresAt)}`);","atom":"a288","author":"pinch","version":34},{"n":177,"text":"\t}","atom":"a288","author":"pinch","version":34},{"n":178,"text":"\treturn { text: lines.join(\"\\n\"), json: { org } };","atom":"a288","author":"pinch","version":34},{"n":179,"text":"}","atom":"a288","author":"pinch","version":34},{"n":180,"text":"","atom":"a288","author":"pinch","version":34},{"n":181,"text":"/** abso init --org with no box signed in to the server: an org's project is made as the person who approved one (abso 663). */","atom":"a2074","author":"box-grants","version":185},{"n":182,"text":"export function initInOrg(org: string, server: string): never {","atom":"a288","author":"pinch","version":34},{"n":183,"text":"\tthrow new UsageError(","atom":"a288","author":"pinch","version":34},{"n":184,"text":"\t\t`this box isn't signed in to ${originOf(server)}, and a project in ${org} is made as a signed-in person. abso login, approving all your projects, then abso init --org ${org} again; or New project at ${siteOf(server)}.`,","atom":"a2074","author":"box-grants","version":185},{"n":185,"text":"\t);","atom":"a288","author":"pinch","version":34},{"n":186,"text":"}","atom":"a288","author":"pinch","version":34}],"atoms":[{"atom":"a288","author":"pinch","message":"","time":1791542950632,"timeIso":"2026-10-09T10:49:10.632Z","publish":{"draft":null,"version":34,"agent":"pinch","message":"Client: abso orgs and abso org <name>, reading as the person who approved this box's sign-in (abso login): your organizations and roles, invitations waiting for you, and an org's projects, people (by name, never id), settings and open invites. Changes (--invite, --role, --remove, --leave, --members, --projects-by), abso org new and abso init --org are made on the website for now; each says where and sends nothing. One change at a time. MCP serves orgs and org. Client tests 283/283, tsc and biome clean.","time":1791543392927,"timeIso":"2026-10-09T10:56:32.927Z"}},{"atom":"a292","author":"pinch","message":"","time":1791543389649,"timeIso":"2026-10-09T10:56:29.649Z","publish":{"draft":null,"version":34,"agent":"pinch","message":"Client: abso orgs and abso org <name>, reading as the person who approved this box's sign-in (abso login): your organizations and roles, invitations waiting for you, and an org's projects, people (by name, never id), settings and open invites. Changes (--invite, --role, --remove, --leave, --members, --projects-by), abso org new and abso init --org are made on the website for now; each says where and sends nothing. One change at a time. MCP serves orgs and org. Client tests 283/283, tsc and biome clean.","time":1791543392927,"timeIso":"2026-10-09T10:56:32.927Z"}},{"atom":"a2074","author":"box-grants","message":"","time":1791994802453,"timeIso":"2026-10-14T16:20:02.453Z","publish":{"draft":null,"version":185,"agent":"box-grants","message":"abso init, init --org and org new from a signed-in box (abso 663). On a server this box is signed in to and with no token for it, abso init makes the project as the person who approved the box, through the server's POST /box/projects (the website's own create): its folder (up to 24 MB) is the first version, --public or --private picks visibility (private by default), --org makes it an organization's project, and one Idempotency-Key per folder (kept in .abso/init-key until it finishes) makes a retry the same project. The folder then joins at once with its own key from the box (--agent, else the box's name). abso org new <name> [--name] makes an organization through POST /box/orgs. abso box and login say 'all of yours, now and later' for a member-all grant. Without a box, init and init --org say to abso login. Tests: orgs, box, help; full suite passes.","time":1791994804231,"timeIso":"2026-10-14T16:20:04.231Z"}}]}