{"draft":null,"from":184,"to":185,"files":[{"path":"client/src/box.ts","added":67,"removed":1,"diff":"--- a/client/src/box.ts\n+++ b/client/src/box.ts\n@@ -21,8 +21,15 @@\n  */\n export interface Grant {\n \treadonly projects: readonly { readonly project: string; readonly role: string }[];\n+\t/** Version 2 grants (abso 663): member-all is every project of the approver's, now and later, at most this role. */\n+\treadonly scopes?: readonly { readonly kind: string; readonly role: string }[];\n }\n \n+/** The role a box has in all its approver's projects, now and later, or null when its grant is a list (abso 663). */\n+export function allProjectsRole(grant: Grant): string | null {\n+\treturn grant.scopes?.find((scope) => scope.kind === \"member-all\")?.role ?? null;\n+}\n+\n /** Requested access is a suggestion for the person approving, never an authorization. */\n export interface LoginRequest {\n \treadonly projects?: readonly { readonly project: string; readonly role: \"reader\" | \"writer\" | \"owner\" }[];\n@@ -154,6 +161,7 @@\n \tbody: unknown,\n \tcredential: string | undefined,\n \tfetcher: typeof fetch,\n+\theaders: Readonly<Record<string, string>> = {},\n ): Promise<Answer> {\n \tconst secrets = credential ? [credential] : [];\n \tlet response: Response;\n@@ -162,6 +170,7 @@\n \t\t\tmethod: \"POST\",\n \t\t\theaders: {\n \t\t\t\t\"content-type\": \"application/json\",\n+\t\t\t\t...headers,\n \t\t\t\t...(credential ? { authorization: `Box ${credential}` } : {}),\n \t\t\t},\n \t\t\tbody: JSON.stringify(body),\n@@ -316,6 +325,60 @@\n \treturn { key, id };\n }\n \n+/** What a new project from this box starts with (abso 663): the website's own create, as the person who approved the box. */\n+export interface NewProject {\n+\treadonly name: string;\n+\treadonly owner?: string;\n+\treadonly visibility?: \"public\" | \"private\";\n+\treadonly files?: readonly (\n+\t\t| { readonly path: string; readonly text: string }\n+\t\t| { readonly path: string; readonly base64: string }\n+\t)[];\n+}\n+\n+/**\n+ * Makes a project as the person who approved this box (abso init, abso 663). One key for every try, so a retry after\n+ * a lost answer or a pending one is the same project, never a second.\n+ */\n+export async function boxCreateProject(\n+\trecord: BoxRecord,\n+\tproject: NewProject,\n+\tkey: string,\n+\tfetcher: typeof fetch = fetch,\n+\tsleep: (ms: number) => Promise<void> = (ms) => new Promise((done) => setTimeout(done, ms)),\n+): Promise<Record<string, unknown>> {\n+\tfor (let attempt = 1; ; attempt++) {\n+\t\tconst a = await call(record.server, \"/box/projects\", project, record.credential, fetcher, {\n+\t\t\t\"Idempotency-Key\": key,\n+\t\t});\n+\t\tconst pending = (a.body.operation as { state?: unknown } | undefined)?.state === \"pending\";\n+\t\tif (!pending) return a.body;\n+\t\tif (attempt >= 10)\n+\t\t\tthrow new UsageError(\n+\t\t\t\t`${originOf(record.server)} is still making ${project.name}. Run the same abso init again in a minute: it picks up where this left off.`,\n+\t\t\t);\n+\t\tawait sleep(1000 * attempt);\n+\t}\n+}\n+\n+/** Makes an organization as the person who approved this box (abso org new, abso 663). */\n+export async function boxCreateOrg(\n+\trecord: BoxRecord,\n+\tname: string,\n+\tdisplayName: string | undefined,\n+\tfetcher: typeof fetch = fetch,\n+): Promise<Record<string, unknown>> {\n+\treturn (\n+\t\tawait call(\n+\t\t\trecord.server,\n+\t\t\t\"/box/orgs\",\n+\t\t\t{ name, ...(displayName === undefined ? {} : { displayName }) },\n+\t\t\trecord.credential,\n+\t\t\tfetcher,\n+\t\t)\n+\t).body;\n+}\n+\n /** The agent name abso join takes when none is given: the box's name, lower-cased. */\n export function defaultAgentName(): string {\n \treturn boxName().toLowerCase();\n@@ -375,9 +438,12 @@\n \tif (!record) return `This box isn't signed in to ${originOf(server)}. abso login signs it in.`;\n \tconst g = record.grant;\n \tconst expired = record.expiresAt <= now;\n+\tconst all = allProjectsRole(g);\n \treturn [\n \t\t`Signed in to ${record.server} as box ${record.id}${expired ? \", but the sign-in has expired. abso login renews it.\" : \".\"}`,\n-\t\t`Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(\", \")}.`,\n+\t\tall === null\n+\t\t\t? `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(\", \")}.`\n+\t\t\t: `Projects: all of yours, now and later (${all} at most). abso init makes a new one; abso org new makes an organization.`,\n \t\t`${expired ? \"Expired\" : \"Expires\"} ${day(record.expiresAt)} UTC.`,\n \t].join(\"\\n\");\n }"}],"unmatched":[]}