@inhera/cli 0.0.0-stage → 0.1.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/README.md +21 -2
- package/bin/inhera.mjs +339 -0
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @inhera/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Inhera command line: workspaces, assets, documents, contracts, members, votes, the activity log and exports, from a terminal, a script or a scheduled job. One file, no dependencies, Node 20 or newer.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install -g @inhera/cli # or: npx @inhera/cli …
|
|
7
|
+
inhera login --key inh_live_… # a key from Account → API access & CLI
|
|
8
|
+
inhera whoami
|
|
9
|
+
inhera use "Harbor Family"
|
|
10
|
+
inhera assets list
|
|
11
|
+
inhera documents upload ~/Desktop/deed.pdf --name "Deed, Harbor Lane" --kind deed
|
|
12
|
+
inhera export --out harbor-$(date +%F).zip
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
A key acts as you, with your role in each workspace, narrowed to the permissions you ticked when you made it, and optionally to one workspace. The vault is never reachable with a key.
|
|
16
|
+
|
|
17
|
+
- `--json` on any command gives machine-readable output; errors come back as `{ "error", "code" }`.
|
|
18
|
+
- `INHERA_API_KEY` in the environment overrides the saved key (servers, CI). `INHERA_API` points at another server, for example staging. `INHERA_WORKSPACE` sets the default workspace.
|
|
19
|
+
- The saved key lives in `~/.config/inhera/config.json`, readable by you only.
|
|
20
|
+
- Exit codes: 0 ok, 1 error, 2 usage, 3 not signed in or key refused, 4 permission denied.
|
|
21
|
+
|
|
22
|
+
Full guide and the REST endpoints: https://inhera.app/developers
|
package/bin/inhera.mjs
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The Inhera command line. One file, no dependencies, Node 20 or newer.
|
|
3
|
+
// Signs every request with an API key made in Account → API access & CLI.
|
|
4
|
+
//
|
|
5
|
+
// inhera login [--key inh_live_…] [--api https://inhera.app]
|
|
6
|
+
// inhera whoami | workspaces | use <workspace>
|
|
7
|
+
// inhera assets list|get|create|import|template
|
|
8
|
+
// inhera documents list|get|upload|download
|
|
9
|
+
// inhera contracts list|get
|
|
10
|
+
// inhera members list|invite
|
|
11
|
+
// inhera votes list|open|ballot
|
|
12
|
+
// inhera activity | export | api <METHOD> <path>
|
|
13
|
+
//
|
|
14
|
+
// Exit codes: 0 ok, 1 error, 2 usage, 3 not signed in / key refused, 4 permission denied.
|
|
15
|
+
|
|
16
|
+
import { createInterface } from "node:readline";
|
|
17
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync, unlinkSync, chmodSync, statSync } from "node:fs";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { basename, join, resolve } from "node:path";
|
|
20
|
+
|
|
21
|
+
const VERSION = "0.1.0";
|
|
22
|
+
const DEFAULT_API = "https://inhera.app";
|
|
23
|
+
const CONFIG_DIR = process.env.INHERA_CONFIG_DIR || join(homedir(), ".config", "inhera");
|
|
24
|
+
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Arguments
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
const argv = process.argv.slice(2);
|
|
31
|
+
const flags = {}; const positional = [];
|
|
32
|
+
for (let i = 0; i < argv.length; i++) {
|
|
33
|
+
const a = argv[i];
|
|
34
|
+
if (a === "--") { positional.push(...argv.slice(i + 1)); break; }
|
|
35
|
+
if (a.startsWith("--")) {
|
|
36
|
+
const eq = a.indexOf("=");
|
|
37
|
+
const name = eq > 0 ? a.slice(2, eq) : a.slice(2);
|
|
38
|
+
let value = eq > 0 ? a.slice(eq + 1) : (argv[i + 1] !== undefined && !argv[i + 1].startsWith("--") ? argv[++i] : true);
|
|
39
|
+
if (name in flags) flags[name] = [].concat(flags[name], value); else flags[name] = value;
|
|
40
|
+
} else positional.push(a);
|
|
41
|
+
}
|
|
42
|
+
const JSON_OUT = Boolean(flags.json);
|
|
43
|
+
const [command, sub, ...rest] = positional;
|
|
44
|
+
|
|
45
|
+
class CliError extends Error { constructor(message, code = 1) { super(message); this.code = code; } }
|
|
46
|
+
const fail = (message, code = 1) => { throw new CliError(message, code); };
|
|
47
|
+
const out = (s = "") => process.stdout.write(`${s}\n`);
|
|
48
|
+
const emit = (data, human) => { if (JSON_OUT) out(JSON.stringify(data, null, 2)); else human(); };
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Config
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
function readConfig() { try { return JSON.parse(readFileSync(CONFIG_FILE, "utf8")); } catch { return {}; } }
|
|
55
|
+
function writeConfig(cfg) {
|
|
56
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
57
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2) + "\n", { mode: 0o600 });
|
|
58
|
+
try { chmodSync(CONFIG_FILE, 0o600); } catch { /* Windows */ }
|
|
59
|
+
}
|
|
60
|
+
const config = readConfig();
|
|
61
|
+
const API = String(flags.api || process.env.INHERA_API || config.api || DEFAULT_API).replace(/\/+$/, "");
|
|
62
|
+
const KEY = process.env.INHERA_API_KEY || config.key || null;
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// HTTP
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
async function call(method, path, { body, form, raw = false, key = KEY } = {}) {
|
|
69
|
+
if (!key) fail("Not signed in. Run `inhera login` with a key from Account → API access & CLI.", 3);
|
|
70
|
+
const headers = { authorization: `Bearer ${key}`, "user-agent": `inhera-cli/${VERSION}` };
|
|
71
|
+
let payload;
|
|
72
|
+
if (form) payload = form;
|
|
73
|
+
else if (body !== undefined) { headers["content-type"] = "application/json"; payload = JSON.stringify(body); }
|
|
74
|
+
let res;
|
|
75
|
+
try { res = await fetch(`${API}${path}`, { method, headers, body: payload }); }
|
|
76
|
+
catch (e) { fail(`Couldn't reach ${API}: ${e.message}`); }
|
|
77
|
+
if (raw) {
|
|
78
|
+
if (!res.ok) { const err = await res.json().catch(() => ({})); throw httpError(res.status, err); }
|
|
79
|
+
return res;
|
|
80
|
+
}
|
|
81
|
+
const type = res.headers.get("content-type") || "";
|
|
82
|
+
const data = type.includes("json") ? await res.json().catch(() => ({})) : await res.text();
|
|
83
|
+
if (!res.ok) throw httpError(res.status, data);
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
function httpError(status, data) {
|
|
87
|
+
const message = (data && typeof data === "object" && data.error) || `HTTP ${status}`;
|
|
88
|
+
if (status === 401) return new CliError(`${message} (run \`inhera login\` with a valid key)`, 3);
|
|
89
|
+
if (status === 403) return new CliError(message, 4);
|
|
90
|
+
if (status === 402) return new CliError(`${message} (the workspace owner's plan is read-only)`, 4);
|
|
91
|
+
return new CliError(message, 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// Helpers
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
function table(rows, columns) {
|
|
99
|
+
if (rows.length === 0) { out("(nothing)"); return; }
|
|
100
|
+
const cells = rows.map((r) => columns.map(([, get]) => String(get(r) ?? "")));
|
|
101
|
+
const widths = columns.map(([h], i) => Math.min(60, Math.max(h.length, ...cells.map((c) => c[i].length))));
|
|
102
|
+
const line = (parts) => parts.map((p, i) => p.slice(0, widths[i]).padEnd(widths[i])).join(" ");
|
|
103
|
+
out(line(columns.map(([h]) => h)));
|
|
104
|
+
out(line(widths.map((w) => "-".repeat(w))));
|
|
105
|
+
for (const c of cells) out(line(c));
|
|
106
|
+
}
|
|
107
|
+
const money = (cents, currency = "USD") => { try { return new Intl.NumberFormat("en-US", { style: "currency", currency, maximumFractionDigits: 0 }).format((cents || 0) / 100); } catch { return `${currency} ${(cents || 0) / 100}`; } };
|
|
108
|
+
const day = (s) => (s ? String(s).slice(0, 10) : "");
|
|
109
|
+
const flag = (name, fallback) => (flags[name] === undefined || flags[name] === true ? fallback : String(flags[name]));
|
|
110
|
+
const need = (value, what) => value ?? fail(`Missing ${what}.`, 2);
|
|
111
|
+
|
|
112
|
+
async function ask(prompt, { hidden = false } = {}) {
|
|
113
|
+
if (!process.stdin.isTTY) fail(`${prompt} is required when not in a terminal; pass it as a flag.`, 2);
|
|
114
|
+
return new Promise((resolveAnswer) => {
|
|
115
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
116
|
+
if (hidden) { rl._writeToOutput = (s) => { if (s.includes(prompt)) process.stdout.write(prompt); }; }
|
|
117
|
+
rl.question(`${prompt}: `, (answer) => { rl.close(); if (hidden) process.stdout.write("\n"); resolveAnswer(answer.trim()); });
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let workspacesCache = null;
|
|
122
|
+
async function workspaces() { if (!workspacesCache) workspacesCache = (await call("GET", "/api/workspaces")).workspaces; return workspacesCache; }
|
|
123
|
+
/** The workspace for this command: --workspace, INHERA_WORKSPACE, the saved default, or the only one. Accepts an id or a name. */
|
|
124
|
+
async function workspaceId() {
|
|
125
|
+
const list = await workspaces();
|
|
126
|
+
const find = (want) => list.find((x) => x.id === want) || list.find((x) => x.name.toLowerCase() === String(want).toLowerCase());
|
|
127
|
+
if (flags.workspace) {
|
|
128
|
+
const w = find(flags.workspace);
|
|
129
|
+
if (w) return w.id;
|
|
130
|
+
// An id the key can't see: let the server answer, so a permission problem reads as one.
|
|
131
|
+
if (/^[0-9a-f-]{20,}$/i.test(String(flags.workspace))) return String(flags.workspace);
|
|
132
|
+
fail(`No workspace "${flags.workspace}" among the ${list.length} this key can see. Try \`inhera workspaces\`.`, 2);
|
|
133
|
+
}
|
|
134
|
+
// The saved or environment default, when this key can see it; otherwise the only workspace it can.
|
|
135
|
+
const preset = process.env.INHERA_WORKSPACE || config.workspace;
|
|
136
|
+
const w = preset ? find(preset) : null;
|
|
137
|
+
if (w) return w.id;
|
|
138
|
+
if (list.length === 1) return list[0].id;
|
|
139
|
+
if (list.length === 0) fail("This key can't see any workspace.", 4);
|
|
140
|
+
fail("Several workspaces: pick one with --workspace <id|name>, or set a default with `inhera use <workspace>`.", 2);
|
|
141
|
+
}
|
|
142
|
+
const W = async () => `/api/workspaces/${await workspaceId()}`;
|
|
143
|
+
|
|
144
|
+
const MIME = { pdf: "application/pdf", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", heic: "image/heic", txt: "text/plain", md: "text/markdown", csv: "text/csv", doc: "application/msword", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", xls: "application/vnd.ms-excel", xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ppt: "application/vnd.ms-powerpoint", pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation", json: "application/json", zip: "application/zip" };
|
|
145
|
+
const mimeOf = (path) => MIME[(path.split(".").pop() || "").toLowerCase()] || "application/octet-stream";
|
|
146
|
+
|
|
147
|
+
function fileForm(path, fields = {}) {
|
|
148
|
+
const abs = resolve(path);
|
|
149
|
+
if (!existsSync(abs)) fail(`No such file: ${path}`, 2);
|
|
150
|
+
if (statSync(abs).size > 200 * 1024 * 1024) fail("Files over 200 MB go through the app's resumable upload; the CLI keeps to 200 MB.", 2);
|
|
151
|
+
const form = new FormData();
|
|
152
|
+
form.append("file", new Blob([readFileSync(abs)], { type: mimeOf(abs) }), basename(abs));
|
|
153
|
+
for (const [k, v] of Object.entries(fields)) if (v !== undefined && v !== null && v !== "") form.append(k, String(v));
|
|
154
|
+
return form;
|
|
155
|
+
}
|
|
156
|
+
async function saveResponse(res, outPath, fallbackName) {
|
|
157
|
+
const cd = res.headers.get("content-disposition") || "";
|
|
158
|
+
const suggested = /filename="?([^";]+)"?/.exec(cd)?.[1] || fallbackName;
|
|
159
|
+
const target = resolve(outPath || suggested);
|
|
160
|
+
writeFileSync(target, Buffer.from(await res.arrayBuffer()));
|
|
161
|
+
return target;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// Commands
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
const commands = {
|
|
169
|
+
async login() {
|
|
170
|
+
const key = flag("key") || (await ask("API key (inh_live_…)", { hidden: true }));
|
|
171
|
+
if (!/^inh_[a-z]+_[0-9a-f]{64}$/.test(key)) fail("That doesn't look like an Inhera API key (inh_live_ followed by 64 characters).", 2);
|
|
172
|
+
const me = await call("GET", "/api/me", { key });
|
|
173
|
+
writeConfig({ ...config, api: API, key, workspace: flags.workspace ? String(flags.workspace) : config.workspace });
|
|
174
|
+
emit({ ok: true, api: API, email: me.user.email, key: me.user.apiKey?.name, scopes: me.user.apiKey?.scopes ?? [] }, () => {
|
|
175
|
+
out(`Signed in to ${API} as ${me.user.email} with key "${me.user.apiKey?.name}". Saved to ${CONFIG_FILE}.`);
|
|
176
|
+
out(`Permissions: ${(me.user.apiKey?.scopes ?? []).join(", ")}`);
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
async logout() {
|
|
180
|
+
if (existsSync(CONFIG_FILE)) unlinkSync(CONFIG_FILE);
|
|
181
|
+
emit({ ok: true }, () => out("Signed out; the saved key was removed from this computer. Revoke it in your account if it shouldn't be used again."));
|
|
182
|
+
},
|
|
183
|
+
async whoami() {
|
|
184
|
+
const me = await call("GET", "/api/me");
|
|
185
|
+
emit({ api: API, user: { id: me.user.id, email: me.user.email, name: me.user.name }, key: me.user.apiKey, workspaces: me.workspaces.length }, () => {
|
|
186
|
+
out(`${me.user.name || me.user.email} <${me.user.email}> on ${API}`);
|
|
187
|
+
if (me.user.apiKey) out(`Key "${me.user.apiKey.name}"${me.user.apiKey.workspaceId ? " (one workspace)" : ""}: ${me.user.apiKey.scopes.join(", ")}`);
|
|
188
|
+
out(`${me.workspaces.length} workspace${me.workspaces.length === 1 ? "" : "s"} visible.`);
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
async workspaces() {
|
|
192
|
+
const list = await workspaces();
|
|
193
|
+
emit({ workspaces: list }, () => table(list, [["id", (w) => w.id], ["name", (w) => w.name], ["kind", (w) => w.kind], ["role", (w) => w.role], ["members", (w) => w.members]]));
|
|
194
|
+
},
|
|
195
|
+
async use() {
|
|
196
|
+
const want = need(sub, "a workspace id or name");
|
|
197
|
+
const list = await workspaces();
|
|
198
|
+
const w = list.find((x) => x.id === want) || list.find((x) => x.name.toLowerCase() === want.toLowerCase());
|
|
199
|
+
if (!w) fail(`No workspace "${want}". Try \`inhera workspaces\`.`, 2);
|
|
200
|
+
writeConfig({ ...config, workspace: w.id });
|
|
201
|
+
emit({ ok: true, workspace: w }, () => out(`Default workspace: ${w.name} (${w.id}).`));
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
async assets() {
|
|
205
|
+
const base = `${await W()}/assets`;
|
|
206
|
+
switch (sub || "list") {
|
|
207
|
+
case "list": { const r = await call("GET", base); emit(r, () => table(r.assets, [["id", (a) => a.id], ["name", (a) => a.name], ["kind", (a) => a.kind], ["value", (a) => money(a.valueCents, a.currency)], ["valued on", (a) => day(a.valuedOn)], ["status", (a) => a.status]])); return; }
|
|
208
|
+
case "get": { const r = await call("GET", `${base}/${need(rest[0], "an asset id")}`); emit(r, () => { const a = r.asset; out(`${a.name} (${a.kind}) · ${money(a.valueCents, a.currency)}${a.valuedOn ? ` as of ${day(a.valuedOn)}` : ""}`); if (a.description) out(a.description); if (a.location) out(`Location: ${a.location}`); if (a.institution) out(`Institution: ${a.institution}`); out(`Documents: ${a.documents} · visibility: ${a.visibility} · id ${a.id}`); if (r.history?.length) { out("\nValue history:"); table(r.history, [["date", (v) => day(v.valuedOn)], ["value", (v) => money(v.valueCents, a.currency)], ["source", (v) => v.source], ["note", (v) => v.note]]); } }); return; }
|
|
209
|
+
case "create": {
|
|
210
|
+
let body = flags.from ? JSON.parse(readFileSync(resolve(String(flags.from)), "utf8")) : {};
|
|
211
|
+
const map = { name: "name", kind: "kind", description: "description", "valued-on": "valuedOn", location: "location", institution: "institution", identifier: "identifier", notes: "notes", "acquired-on": "acquiredOn", visibility: "visibility" };
|
|
212
|
+
for (const [f, k] of Object.entries(map)) if (flags[f] !== undefined) body[k] = String(flags[f]);
|
|
213
|
+
if (flags.value !== undefined) body.value = Number(String(flags.value).replace(/[,$]/g, ""));
|
|
214
|
+
if (flags["cost-basis"] !== undefined) body.costBasis = Number(String(flags["cost-basis"]).replace(/[,$]/g, ""));
|
|
215
|
+
if (!body.name) fail("--name is required (or --from file.json).", 2);
|
|
216
|
+
const r = await call("POST", base, { body });
|
|
217
|
+
emit(r, () => out(`Created ${r.asset.name} (${r.asset.id}).`)); return;
|
|
218
|
+
}
|
|
219
|
+
case "value": { const id = need(rest[0], "an asset id"); const value = Number(String(need(rest[1], "a value")).replace(/[,$]/g, "")); const r = await call("POST", `${base}/${id}/values`, { body: { value, valuedOn: flag("valued-on", new Date().toISOString().slice(0, 10)), source: flag("source", "manual"), note: flag("note", "") } }); emit(r, () => out(`Recorded ${money(value * 100)} for ${id}.`)); return; }
|
|
220
|
+
case "template": { const res = await call("GET", `${base}/import/template`, { raw: true }); out((await res.text()).trim()); return; }
|
|
221
|
+
case "import": {
|
|
222
|
+
const path = need(rest[0], "a CSV file"); const csv = readFileSync(resolve(path), "utf8");
|
|
223
|
+
const r = await call("POST", `${base}/import`, { body: { csv, dryRun: Boolean(flags["dry-run"]) } });
|
|
224
|
+
const okRows = (r.rows || []).filter((x) => x.ok).length, bad = (r.rows || []).filter((x) => !x.ok);
|
|
225
|
+
emit(r, () => { out(r.dryRun ? `Dry run: ${okRows} asset(s) would be created${bad.length ? `, ${bad.length} row(s) have problems` : ""}.` : `Imported ${r.imported} asset(s).`); for (const x of bad) out(` line ${x.line}: ${x.errors.join("; ")}`); if (r.unknownColumns?.length) out(`Ignored columns: ${r.unknownColumns.join(", ")}`); }); return;
|
|
226
|
+
}
|
|
227
|
+
default: fail(`Unknown: assets ${sub}. Try list, get, create, value, import, template.`, 2);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
async documents() {
|
|
232
|
+
const base = `${await W()}/documents`;
|
|
233
|
+
switch (sub || "list") {
|
|
234
|
+
case "list": { const r = await call("GET", base); emit(r, () => table(r.documents, [["id", (d) => d.id], ["name", (d) => d.name], ["kind", (d) => d.kind], ["version", (d) => d.currentVersion ?? d.version ?? ""], ["expires", (d) => day(d.expiresOn)], ["updated", (d) => day(d.updatedAt)]])); return; }
|
|
235
|
+
case "get": { const r = await call("GET", `${base}/${need(rest[0], "a document id")}`); emit(r, () => { const d = r.document; out(`${d.name} (${d.kind}) · ${d.fileName || ""} ${d.size ? `${Math.round(d.size / 1024)} KB` : ""}`); if (d.description) out(d.description); out(`Visibility ${d.visibility}${d.expiresOn ? ` · expires ${day(d.expiresOn)}` : ""} · id ${d.id}`); }); return; }
|
|
236
|
+
case "upload": {
|
|
237
|
+
const path = need(rest[0], "a file");
|
|
238
|
+
const form = fileForm(path, { name: flags.name, kind: flags.kind, description: flags.description, expiresOn: flags["expires-on"], assetId: flags.asset, visibility: flags.visibility });
|
|
239
|
+
const r = await call("POST", base, { form });
|
|
240
|
+
emit(r, () => out(`Uploaded ${r.document.name} (${r.document.id}).`)); return;
|
|
241
|
+
}
|
|
242
|
+
case "version": { const id = need(rest[0], "a document id"); const form = fileForm(need(rest[1], "a file"), { note: flags.note }); const r = await call("POST", `${base}/${id}/versions`, { form }); emit(r, () => out(`New version of ${r.document?.name || id}.`)); return; }
|
|
243
|
+
case "download": {
|
|
244
|
+
const id = need(rest[0], "a document id");
|
|
245
|
+
const res = await call("GET", `${base}/${id}/file?download=1`, { raw: true });
|
|
246
|
+
const target = await saveResponse(res, flags.out, `${id}.bin`);
|
|
247
|
+
emit({ ok: true, path: target }, () => out(`Saved ${target}`)); return;
|
|
248
|
+
}
|
|
249
|
+
default: fail(`Unknown: documents ${sub}. Try list, get, upload, version, download.`, 2);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
async contracts() {
|
|
254
|
+
const base = `${await W()}/contracts`;
|
|
255
|
+
switch (sub || "list") {
|
|
256
|
+
case "list": { const r = await call("GET", base); emit(r, () => table(r.contracts, [["id", (k) => k.id], ["title", (k) => k.title], ["kind", (k) => k.kind], ["status", (k) => k.status], ["parties", (k) => (k.parties || []).length], ["expires", (k) => day(k.expiresOn)]])); return; }
|
|
257
|
+
case "get": { const r = await call("GET", `${base}/${need(rest[0], "a contract id")}`); emit(r, () => { const k = r.contract; out(`${k.title} (${k.kind}) · ${k.status} · version ${k.currentVersion}`); if (k.parties?.length) table(k.parties, [["party", (p) => p.name || p.email], ["role", (p) => p.role], ["status", (p) => p.status], ["signed", (p) => day(p.signedAt)]]); out(`\n${k.body}`); }); return; }
|
|
258
|
+
default: fail(`Unknown: contracts ${sub}. Try list, get.`, 2);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
async members() {
|
|
263
|
+
const base = await W();
|
|
264
|
+
switch (sub || "list") {
|
|
265
|
+
case "list": { const r = await call("GET", base); emit({ members: r.members }, () => table(r.members, [["email", (m) => m.email], ["name", (m) => m.displayName], ["role", (m) => m.role], ["status", (m) => m.status], ["last seen", (m) => day(m.lastSeenAt)]])); return; }
|
|
266
|
+
case "invite": { const email = need(rest[0], "an email address"); const r = await call("POST", `${base}/invites`, { body: { email, role: flag("role", "member"), displayName: flag("name", ""), message: flag("message", "") } }); emit(r, () => out(`Invited ${email} as ${flag("role", "member")}.`)); return; }
|
|
267
|
+
default: fail(`Unknown: members ${sub}. Try list, invite.`, 2);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
async votes() {
|
|
272
|
+
const base = `${await W()}/votes`;
|
|
273
|
+
switch (sub || "list") {
|
|
274
|
+
case "list": { const r = await call("GET", base); emit(r, () => table(r.votes, [["id", (v) => v.id], ["title", (v) => v.title], ["status", (v) => v.status], ["closes", (v) => day(v.closesAt)], ["cast", (v) => `${v.cast}/${v.eligible}`], ["outcome", (v) => v.outcome]])); return; }
|
|
275
|
+
case "open": case "request": {
|
|
276
|
+
const options = [].concat(flags.option || []).filter(Boolean);
|
|
277
|
+
const body = { title: need(flag("title"), "--title"), question: flag("question", ""), kind: options.length ? "choice" : "yes_no", options, closesAt: need(flag("closes"), "--closes YYYY-MM-DD"), quorumPct: Number(flag("quorum", "50")), thresholdPct: Number(flag("threshold", "50")), anonymous: Boolean(flags.anonymous), note: flag("note", "") };
|
|
278
|
+
const r = await call("POST", base, { body });
|
|
279
|
+
emit(r, () => out(`${r.vote.status === "open" ? "Opened" : "Requested"} "${r.vote.title}" (${r.vote.id}), ${r.vote.eligible} voter(s).`)); return;
|
|
280
|
+
}
|
|
281
|
+
case "ballot": { const id = need(rest[0], "a vote id"); const choice = need(rest[1], "a choice"); const r = await call("POST", `${base}/${id}/ballot`, { body: { choice, note: flag("note", "") } }); emit(r, () => out(`Ballot cast: ${choice}. ${r.vote.cast} of ${r.vote.eligible} have voted${r.vote.status === "closed" ? `; the vote is closed: ${r.vote.outcome}` : ""}.`)); return; }
|
|
282
|
+
default: fail(`Unknown: votes ${sub}. Try list, open, request, ballot.`, 2);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
async activity() {
|
|
287
|
+
const r = await call("GET", `${await W()}/audit`);
|
|
288
|
+
const limit = Number(flag("limit", "50"));
|
|
289
|
+
emit(r, () => table(r.entries.slice(0, limit), [["when", (e) => String(e.createdAt).slice(0, 16)], ["who", (e) => e.actor], ["what", (e) => e.summary]]));
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
async export() {
|
|
293
|
+
const dataOnly = Boolean(flags["data-only"]);
|
|
294
|
+
const res = await call("GET", `${await W()}/export${dataOnly ? "?files=0" : ""}`, { raw: true });
|
|
295
|
+
const target = await saveResponse(res, flags.out, `inhera-export.zip`);
|
|
296
|
+
emit({ ok: true, path: target }, () => out(`Saved ${target}`));
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
async api() {
|
|
300
|
+
const method = String(need(sub, "a method (GET, POST, PUT, DELETE)")).toUpperCase();
|
|
301
|
+
const path = need(rest[0], "a path like /api/workspaces");
|
|
302
|
+
const body = flags.data ? JSON.parse(String(flags.data)) : undefined;
|
|
303
|
+
const r = await call(method, path.startsWith("/") ? path : `/${path}`, { body });
|
|
304
|
+
out(typeof r === "string" ? r : JSON.stringify(r, null, 2));
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
version() { out(VERSION); },
|
|
308
|
+
help() {
|
|
309
|
+
out(`inhera ${VERSION}: the Inhera command line.
|
|
310
|
+
|
|
311
|
+
inhera login [--key inh_live_…] [--api URL] save a key for this computer
|
|
312
|
+
inhera logout | whoami | workspaces | use <workspace>
|
|
313
|
+
inhera assets list | get <id> | create --name … [--kind --value --valued-on --description --location --institution] | value <id> <amount> | import <file.csv> [--dry-run] | template
|
|
314
|
+
inhera documents list | get <id> | upload <file> [--name --kind --description --expires-on --asset] | version <id> <file> | download <id> [--out path]
|
|
315
|
+
inhera contracts list | get <id>
|
|
316
|
+
inhera members list | invite <email> [--role member|admin|advisor|heir|viewer] [--name]
|
|
317
|
+
inhera votes list | open --title … --closes YYYY-MM-DD [--question --option A --option B --quorum --threshold --anonymous] | ballot <id> <choice>
|
|
318
|
+
inhera activity [--limit N]
|
|
319
|
+
inhera export [--out file.zip] [--data-only]
|
|
320
|
+
inhera api <METHOD> <path> [--data '{"…":…}']
|
|
321
|
+
|
|
322
|
+
Everywhere: --json for machine-readable output, --workspace <id|name> for one command, --api <url> for staging.
|
|
323
|
+
Keys: Account → API access & CLI at ${DEFAULT_API}. Guide: ${DEFAULT_API}/developers`);
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// ---------------------------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const name = !command || flags.help ? "help" : flags.version ? "version" : command;
|
|
331
|
+
const fn = commands[name];
|
|
332
|
+
if (!fn) fail(`Unknown command "${command}". Try \`inhera help\`.`, 2);
|
|
333
|
+
await fn();
|
|
334
|
+
} catch (e) {
|
|
335
|
+
const code = e instanceof CliError ? e.code : 1;
|
|
336
|
+
if (JSON_OUT) out(JSON.stringify({ error: e.message, code }));
|
|
337
|
+
else process.stderr.write(`inhera: ${e.message}\n`);
|
|
338
|
+
process.exit(code);
|
|
339
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inhera/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Inhera command line: workspaces, assets, documents, contracts, members, votes, activity and exports from a terminal or a script, behind an API key you make in your account.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": { "inhera": "bin/inhera.mjs" },
|
|
8
|
+
"files": ["bin", "README.md"],
|
|
9
|
+
"engines": { "node": ">=20" },
|
|
10
|
+
"keywords": ["inhera", "estate", "family-office", "cli"],
|
|
11
|
+
"homepage": "https://inhera.app/developers",
|
|
12
|
+
"repository": { "type": "git", "url": "https://github.com/Inhera-App/Inhera-App", "directory": "cli" }
|
|
13
|
+
}
|