@hive3/cli 0.1.0 → 0.2.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 CHANGED
@@ -11,6 +11,20 @@ hive whoami
11
11
  hive capabilities
12
12
  ```
13
13
 
14
+ The package installs both command names. Use `hive` or `hive3` interchangeably:
15
+
16
+ ```bash
17
+ hive3 login
18
+ hive3 whoami
19
+ ```
20
+
21
+ By default, `hive login` opens an approval page where the signed-in user chooses either Read Only or Full Access. Scripted logins can preselect a bundle:
22
+
23
+ ```bash
24
+ hive login --access read
25
+ hive login --access full
26
+ ```
27
+
14
28
  The CLI stores credentials in the OS config directory, or `HIVE_CONFIG_HOME` when set. It prints approval URLs, codes, key prefixes, and config paths, but never prints the API key secret after login completion.
15
29
 
16
30
  Useful environment overrides:
@@ -21,6 +35,13 @@ Useful environment overrides:
21
35
 
22
36
  ## Scopes
23
37
 
38
+ Most users should use the login approval page's Read Only or Full Access choice:
39
+
40
+ - Read Only: read account, community capability, post, and resource data.
41
+ - Full Access: read/write API capabilities, including community admin actions where the person already has the live role. Account deletion requests still require an explicit confirmation command.
42
+
43
+ Advanced users can request exact scopes with repeated `--scope` flags.
44
+
24
45
  - `account:read` and `account:write`: profile, account preferences, wallets visibility, NFT exposure, export/deletion requests, uploads, and builder config.
25
46
  - `posts:read` and `posts:write`: posts and comments.
26
47
  - `resources:read` and `resources:write`: events, courses, content, quests, jobs, participant workflows, evidence, attendance, progress, and applications.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive3/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Command-line client for Hive's public API.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/api-client.js CHANGED
@@ -196,6 +196,9 @@ export function createApiClient(options) {
196
196
  requestAccountExport() {
197
197
  return request("POST", "/account/export");
198
198
  },
199
+ revokeCurrentKey() {
200
+ return request("DELETE", "/account/keys/current");
201
+ },
199
202
  saveBuilder(kind, config) {
200
203
  return request("PATCH", `/profile/${kind}`, { body: { config } });
201
204
  },
package/src/commands.js CHANGED
@@ -424,8 +424,9 @@ async function runUpload(args, deps) {
424
424
  const fileName = path.basename(filePath);
425
425
  const client = await authenticatedClient(deps);
426
426
  const issued = await client.createUploadUrl({ byteSize: fileStat.size, contentType, fileName, purpose });
427
+ const { uploadUrl, ...issuedSafe } = issued.data;
427
428
  const bytes = await readFile(filePath);
428
- const response = await deps.fetch(issued.data.uploadUrl, {
429
+ const response = await deps.fetch(uploadUrl, {
429
430
  body: new Blob([bytes], { type: contentType }),
430
431
  headers: { "Content-Type": contentType },
431
432
  method: "POST",
@@ -435,7 +436,7 @@ async function runUpload(args, deps) {
435
436
  if (!response.ok) {
436
437
  throw new HiveApiError(`Upload failed with status ${response.status}`, { code: "upload_failed", status: response.status });
437
438
  }
438
- writeJson(deps.stdout, { data: { ...issued.data, ...parsed } });
439
+ writeJson(deps.stdout, { data: { ...issuedSafe, ...parsed } });
439
440
  }
440
441
 
441
442
  async function runAccount(args, deps) {
@@ -551,6 +552,22 @@ export async function main(argv, overrides = {}) {
551
552
  return 0;
552
553
  }
553
554
  if (command === "logout") {
555
+ try {
556
+ const config = await loadConfig({ env: deps.env, homeDir: deps.homeDir, platform: deps.platform });
557
+ if (config?.apiKey) {
558
+ await createApiClient({
559
+ apiBaseUrl: config.apiBaseUrl,
560
+ apiKey: config.apiKey,
561
+ fetch: deps.fetch,
562
+ }).revokeCurrentKey();
563
+ writeLine(deps.stdout, "Revoked the server credential.");
564
+ }
565
+ } catch {
566
+ writeLine(
567
+ deps.stderr,
568
+ "Warning: could not revoke the server credential. Revoke it at Settings → Developer credentials.",
569
+ );
570
+ }
554
571
  const file = await clearConfig({ env: deps.env, homeDir: deps.homeDir, platform: deps.platform });
555
572
  writeLine(deps.stdout, `Removed Hive CLI credential at ${file}.`);
556
573
  return 0;
package/src/config.js CHANGED
@@ -78,8 +78,9 @@ export async function saveCredential(credential, options, overrides = {}) {
78
78
  keyPrefix: credential.keyPrefix,
79
79
  scopes: credential.scopes,
80
80
  };
81
- await fs.writeFile(file, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
82
- await fs.chmod(file, 0o600);
81
+ const tmp = `${file}.${process.pid}.tmp`;
82
+ await fs.writeFile(tmp, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
83
+ await fs.rename(tmp, file);
83
84
  return file;
84
85
  }
85
86
 
package/src/login.js CHANGED
@@ -8,6 +8,7 @@ import { saveCredential } from "./config.js";
8
8
  export const DEFAULT_API_BASE_URL = "https://app.hive3.tech/api/v1";
9
9
  export const DEFAULT_APP_URL = "https://app.hive3.tech";
10
10
  export const DEFAULT_LABEL = "Hive CLI";
11
+ export const DEFAULT_PERMISSION_MODE = "select";
11
12
  export const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
12
13
 
13
14
  export function loginUsage() {
@@ -15,10 +16,11 @@ export function loginUsage() {
15
16
  "Usage: hive login [options]",
16
17
  "",
17
18
  "Options:",
19
+ " --access <read|full> Permission bundle to approve; omit to choose in browser",
18
20
  " --api-url <url> Public API base URL",
19
21
  " --app-url <url> Browser app URL for approval",
20
22
  " --label <label> Local credential label",
21
- " --scope <scope> Requested API scope, repeatable",
23
+ " --scope <scope> Advanced: request an exact API scope, repeatable",
22
24
  " --timeout-ms <ms> Login polling timeout",
23
25
  " --no-open Print the URL without opening a browser",
24
26
  " -h, --help Show help",
@@ -36,6 +38,8 @@ export function parseLoginArgs(args, env = process.env) {
36
38
  appUrl: env.HIVE_APP_URL || DEFAULT_APP_URL,
37
39
  label: DEFAULT_LABEL,
38
40
  noOpen: false,
41
+ permissionMode: DEFAULT_PERMISSION_MODE,
42
+ permissionModeExplicit: false,
39
43
  scopes: [],
40
44
  timeoutMs: DEFAULT_TIMEOUT_MS,
41
45
  };
@@ -44,6 +48,12 @@ export function parseLoginArgs(args, env = process.env) {
44
48
  const flag = args[index];
45
49
  if (flag === "--no-open") {
46
50
  options.noOpen = true;
51
+ } else if (flag === "--access" || flag === "--permission") {
52
+ index += 1;
53
+ const value = requiredFlagValue(flag, args[index]);
54
+ if (value !== "read" && value !== "full") throw new Error(`${flag} must be read or full`);
55
+ options.permissionMode = value;
56
+ options.permissionModeExplicit = true;
47
57
  } else if (flag === "--api-url") {
48
58
  index += 1;
49
59
  options.apiBaseUrl = requiredFlagValue(flag, args[index]);
@@ -69,6 +79,9 @@ export function parseLoginArgs(args, env = process.env) {
69
79
  if (!Number.isFinite(options.timeoutMs) || options.timeoutMs <= 0) {
70
80
  throw new Error("--timeout-ms must be a positive number");
71
81
  }
82
+ if (options.permissionModeExplicit && options.scopes.length > 0) {
83
+ throw new Error("--access cannot be combined with --scope. Use one permission bundle or exact scopes.");
84
+ }
72
85
  return { help: false, options };
73
86
  }
74
87
 
@@ -123,11 +136,16 @@ function writeLine(stream, message = "") {
123
136
  export async function login(options, overrides = {}) {
124
137
  const deps = { ...defaultDeps(), ...overrides };
125
138
  const apiBaseUrl = normalizeBaseUrl(options.apiBaseUrl);
126
- const start = await postJson(deps.fetch, `${apiBaseUrl}/cli/auth/start`, {
139
+ const payload = {
127
140
  appUrl: options.appUrl,
128
141
  label: options.label,
129
- scopes: options.scopes.length > 0 ? options.scopes : undefined,
130
- });
142
+ };
143
+ if (options.scopes.length > 0) {
144
+ payload.scopes = options.scopes;
145
+ } else {
146
+ payload.permissionMode = options.permissionMode || DEFAULT_PERMISSION_MODE;
147
+ }
148
+ const start = await postJson(deps.fetch, `${apiBaseUrl}/cli/auth/start`, payload);
131
149
  const data = start.data;
132
150
  // A malformed server response must not turn the poll loop into a busy loop
133
151
  // (NaN/0 sleeps) or a hammering one: fall back to a sane 2s interval.