@hive3/cli 0.3.0 → 0.4.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/src/api-client.js CHANGED
@@ -101,7 +101,7 @@ export function createApiClient(options) {
101
101
 
102
102
  async function request(method, apiPath, requestOptions = {}) {
103
103
  if (!apiKey) {
104
- throw new HiveApiError("Not logged in. Run hive login first.", { code: "auth_required", status: 401 });
104
+ throw new HiveApiError("Not logged in. Run hive3 login first.", { code: "auth_required", status: 401 });
105
105
  }
106
106
  const url = new URL(`${apiBaseUrl}/${apiPath.replace(/^\/+/, "")}`);
107
107
  appendQuery(url, requestOptions.query);
@@ -127,6 +127,7 @@ export function createApiClient(options) {
127
127
  }
128
128
 
129
129
  return {
130
+ apiBaseUrl,
130
131
  archiveResource(kind, id) {
131
132
  return request("DELETE", `/${kind}/${encodeURIComponent(id)}`);
132
133
  },
@@ -157,6 +158,15 @@ export function createApiClient(options) {
157
158
  getAccount() {
158
159
  return request("GET", "/account");
159
160
  },
161
+ getResource(kind, id) {
162
+ return request("GET", `/${kind}/${encodeURIComponent(id)}`);
163
+ },
164
+ getUnreadNotificationCount() {
165
+ return request("GET", "/notifications/unread-count");
166
+ },
167
+ listLinkedCommunities() {
168
+ return request("GET", "/account/linked-communities");
169
+ },
160
170
  getBuilder(kind, account) {
161
171
  return request("GET", `/profile/${kind}`, { query: { account } });
162
172
  },
@@ -190,9 +200,6 @@ export function createApiClient(options) {
190
200
  markNotificationRead(notificationId) {
191
201
  return request("POST", `/notifications/${encodeURIComponent(notificationId)}/read`);
192
202
  },
193
- requestAccountDeletion(confirmation) {
194
- return request("POST", "/account/deletion", { body: { confirmation } });
195
- },
196
203
  requestAccountExport() {
197
204
  return request("POST", "/account/export");
198
205
  },
@@ -249,8 +256,8 @@ export function createApiClient(options) {
249
256
  removeComment(commentId) {
250
257
  return request("DELETE", `/comments/${encodeURIComponent(commentId)}`);
251
258
  },
252
- removeCommunityMember(communityId, memberPersonId) {
253
- return request("DELETE", `/communities/${encodeURIComponent(communityId)}/members/${encodeURIComponent(memberPersonId)}`);
259
+ removeCommunityMember(communityId, memberAccountId) {
260
+ return request("DELETE", `/communities/${encodeURIComponent(communityId)}/members/${encodeURIComponent(memberAccountId)}`);
254
261
  },
255
262
  updateComment(commentId, payload) {
256
263
  return request("PATCH", `/comments/${encodeURIComponent(commentId)}`, { body: payload });
@@ -261,14 +268,86 @@ export function createApiClient(options) {
261
268
  removeWallet(walletAddress) {
262
269
  return request("DELETE", `/wallets/${encodeURIComponent(walletAddress)}`);
263
270
  },
264
- setCommunityRole(communityId, memberPersonId, role) {
265
- return request("PATCH", `/communities/${encodeURIComponent(communityId)}/members/${encodeURIComponent(memberPersonId)}/role`, {
271
+ setCommunityRole(communityId, memberAccountId, role) {
272
+ return request("PATCH", `/communities/${encodeURIComponent(communityId)}/members/${encodeURIComponent(memberAccountId)}/role`, {
266
273
  body: { role },
267
274
  });
268
275
  },
269
276
  updateCommunityAccess(communityId, payload) {
270
277
  return request("PATCH", `/communities/${encodeURIComponent(communityId)}/access`, { body: payload });
271
278
  },
279
+ search(query) {
280
+ return request("GET", "/search", { query });
281
+ },
282
+ listBroadcasts(query) {
283
+ return request("GET", "/broadcasts", { query });
284
+ },
285
+ getBroadcastAudience(account) {
286
+ return request("GET", "/broadcasts/audience", { query: { account } });
287
+ },
288
+ getBroadcast(id) {
289
+ return request("GET", `/broadcasts/${encodeURIComponent(id)}`);
290
+ },
291
+ createBroadcast(payload, account, idempotencyKey) {
292
+ return request("POST", "/broadcasts", { body: payload, idempotencyKey, query: { account } });
293
+ },
294
+ updateBroadcast(id, payload) {
295
+ return request("PATCH", `/broadcasts/${encodeURIComponent(id)}`, { body: payload });
296
+ },
297
+ sendBroadcastTest(id) {
298
+ return request("POST", `/broadcasts/${encodeURIComponent(id)}/test`, { body: {} });
299
+ },
300
+ sendBroadcast(id, payload) {
301
+ return request("POST", `/broadcasts/${encodeURIComponent(id)}/send`, { body: payload });
302
+ },
303
+ cancelBroadcast(id) {
304
+ return request("POST", `/broadcasts/${encodeURIComponent(id)}/cancel`, { body: {} });
305
+ },
306
+ listTickets(query) {
307
+ return request("GET", "/tickets", { query });
308
+ },
309
+ getTicket(id) {
310
+ return request("GET", `/tickets/${encodeURIComponent(id)}`);
311
+ },
312
+ updateTicket(id, payload) {
313
+ return request("PATCH", `/tickets/${encodeURIComponent(id)}`, { body: payload });
314
+ },
315
+ listMyTickets(query) {
316
+ return request("GET", "/tickets/mine", { query });
317
+ },
318
+ getAssistant(account) {
319
+ return request("GET", "/ai-assistant", { query: { account } });
320
+ },
321
+ updateAssistant(payload, account) {
322
+ return request("PATCH", "/ai-assistant", { body: payload, query: { account } });
323
+ },
324
+ listAssistantDocuments(account) {
325
+ return request("GET", "/ai-assistant/documents", { query: { account } });
326
+ },
327
+ createAssistantUploadUrl(account) {
328
+ return request("POST", "/ai-assistant/documents/upload-url", { body: {}, query: { account } });
329
+ },
330
+ createAssistantDocument(payload, account, idempotencyKey) {
331
+ return request("POST", "/ai-assistant/documents", { body: payload, idempotencyKey, query: { account } });
332
+ },
333
+ deleteAssistantDocument(documentId) {
334
+ return request("DELETE", `/ai-assistant/documents/${encodeURIComponent(documentId)}`);
335
+ },
336
+ listCredentials(query) {
337
+ return request("GET", "/credentials", { query });
338
+ },
339
+ getCredential(id) {
340
+ return request("GET", `/credentials/${encodeURIComponent(id)}`);
341
+ },
342
+ awardCredential(id, handles) {
343
+ return request("POST", `/credentials/${encodeURIComponent(id)}/awards`, { body: { handles } });
344
+ },
345
+ listMyCredentials() {
346
+ return request("GET", "/credentials/mine");
347
+ },
348
+ listClaimableCredentials(query) {
349
+ return request("GET", "/credentials/claimable", { query });
350
+ },
272
351
  whoami() {
273
352
  return request("GET", "/me");
274
353
  },
@@ -0,0 +1,385 @@
1
+ // @ts-check
2
+
3
+ import { stat } from "node:fs/promises";
4
+ import path from "node:path";
5
+
6
+ import { HiveApiError } from "./api-client.js";
7
+ import { authenticatedClient, parseBoolean, postFileToUploadUrl, readJsonObject, requiredFlagValue, writeJson } from "./shared.js";
8
+
9
+ /**
10
+ * @typedef {{ key: string, type: "string" | "boolean" | "switch" | "limit" | "choice" | "amount" | "currency" | "iso-date", choices?: string[], max?: number }} FlagRule
11
+ */
12
+
13
+ /** @type {Record<string, FlagRule>} */
14
+ const ACCOUNT = { "--account": { key: "account", type: "string" } };
15
+ /** @type {Record<string, FlagRule>} */
16
+ const PAGING = {
17
+ "--limit": { key: "limit", type: "limit" },
18
+ "--cursor": { key: "cursor", type: "string" },
19
+ };
20
+ /** @type {Record<string, FlagRule>} */
21
+ const IDEMPOTENCY = { "--idempotency-key": { key: "idempotencyKey", type: "string" } };
22
+
23
+ /**
24
+ * Small declarative flag parser shared by the newer command groups. Positional
25
+ * arguments are anything that does not start with `--`.
26
+ * @param {string[]} args
27
+ * @param {Record<string, FlagRule>} spec
28
+ * @param {string} label
29
+ * @param {number} maxPositionals
30
+ */
31
+ function parseArgs(args, spec, label, maxPositionals = 0) {
32
+ /** @type {Record<string, any>} */
33
+ const values = {};
34
+ /** @type {string[]} */
35
+ const positionals = [];
36
+ for (let index = 0; index < args.length; index += 1) {
37
+ const token = args[index];
38
+ if (!token.startsWith("--")) {
39
+ positionals.push(token);
40
+ continue;
41
+ }
42
+ const rule = spec[token];
43
+ if (!rule) throw new Error(`Unknown ${label} option: ${token}`);
44
+ if (rule.type === "switch") {
45
+ values[rule.key] = true;
46
+ continue;
47
+ }
48
+ if (values[rule.key] !== undefined) throw new Error(`${token} may only be given once`);
49
+ index += 1;
50
+ values[rule.key] = convertValue(token, rule, requiredFlagValue(token, args[index]));
51
+ }
52
+ if (positionals.length > maxPositionals) throw new Error(`Unknown ${label} option: ${positionals[maxPositionals]}`);
53
+ return { positionals, values };
54
+ }
55
+
56
+ /**
57
+ * @param {string} flag
58
+ * @param {FlagRule} rule
59
+ * @param {string} raw
60
+ */
61
+ function convertValue(flag, rule, raw) {
62
+ if (rule.type === "boolean") return parseBoolean(raw, flag);
63
+ if (rule.type === "limit") {
64
+ const value = Number(raw);
65
+ const max = rule.max ?? 100;
66
+ if (!Number.isInteger(value) || value < 1 || value > max) throw new Error(`${flag} must be a whole number from 1 to ${max}`);
67
+ return value;
68
+ }
69
+ if (rule.type === "choice") {
70
+ if (!rule.choices?.includes(raw)) throw new Error(`${flag} must be ${rule.choices?.join(", ")}`);
71
+ return raw;
72
+ }
73
+ if (rule.type === "amount") {
74
+ if (!/^\d+(\.\d{1,2})?$/.test(raw) || Number(raw) <= 0) {
75
+ throw new Error(`${flag} must be a positive decimal amount with at most two decimals, for example 10.00`);
76
+ }
77
+ return raw;
78
+ }
79
+ if (rule.type === "currency") {
80
+ if (!/^[A-Za-z]{3}$/.test(raw)) throw new Error(`${flag} must be a three-letter currency code`);
81
+ return raw.toUpperCase();
82
+ }
83
+ if (rule.type === "iso-date") {
84
+ if (Number.isNaN(Date.parse(raw))) throw new Error(`${flag} must be an ISO-8601 date-time such as 2026-12-01T15:00:00Z`);
85
+ return raw;
86
+ }
87
+ return raw;
88
+ }
89
+
90
+ /** @param {string | undefined} value @param {string} name */
91
+ function requiredId(name, value) {
92
+ return requiredFlagValue(name, value);
93
+ }
94
+
95
+ /** @param {Record<string, any>} values @param {string[]} keys */
96
+ function pickDefined(values, keys) {
97
+ /** @type {Record<string, any>} */
98
+ const payload = {};
99
+ for (const key of keys) {
100
+ if (values[key] !== undefined) payload[key] = values[key];
101
+ }
102
+ return payload;
103
+ }
104
+
105
+ function requireChanges(payload, label) {
106
+ if (Object.keys(payload).length === 0) throw new Error(`${label} needs at least one field to change`);
107
+ }
108
+
109
+ function requireExactConfirmation(values, id, noun) {
110
+ if (values.confirm !== id) throw new Error(`--confirm must exactly match the ${noun} id`);
111
+ }
112
+
113
+ // --- search ---------------------------------------------------------------
114
+
115
+ const SEARCH_TYPES = ["all", "accounts", "events", "courses", "content", "quests", "jobs"];
116
+
117
+ async function runSearch(args, deps) {
118
+ const { positionals, values } = parseArgs(args, {
119
+ "--type": { choices: SEARCH_TYPES, key: "type", type: "choice" },
120
+ "--limit": { key: "limit", max: 50, type: "limit" },
121
+ "--cursor": { key: "cursor", type: "string" },
122
+ }, "search", Number.POSITIVE_INFINITY);
123
+ const q = positionals.join(" ").trim();
124
+ if (!q) throw new Error("search query requires a value");
125
+ if (q.length > 100) throw new Error("search query must be 1-100 characters");
126
+ writeJson(deps.stdout, await (await authenticatedClient(deps)).search({ ...values, q }));
127
+ }
128
+
129
+ // --- broadcasts -----------------------------------------------------------
130
+
131
+ /** @type {Record<string, FlagRule>} */
132
+ const BROADCAST_FIELDS = {
133
+ "--subject": { key: "subject", type: "string" },
134
+ "--body-text": { key: "bodyText", type: "string" },
135
+ "--body-html": { key: "bodyHtml", type: "string" },
136
+ "--body-mode": { choices: ["editor", "html"], key: "bodyMode", type: "choice" },
137
+ "--hero-image-url": { key: "heroImageUrl", type: "string" },
138
+ "--file": { key: "file", type: "string" },
139
+ };
140
+
141
+ async function broadcastPayload(values) {
142
+ const fromFile = values.file ? await readJsonObject(values.file) : {};
143
+ return {
144
+ ...fromFile,
145
+ ...pickDefined(values, ["subject", "bodyText", "bodyHtml", "bodyMode", "heroImageUrl"]),
146
+ };
147
+ }
148
+
149
+ async function runBroadcasts(args, deps) {
150
+ const [action, ...rest] = args;
151
+ const client = await authenticatedClient(deps);
152
+ if (action === "list") {
153
+ const { values } = parseArgs(rest, { ...ACCOUNT, ...PAGING }, "broadcasts list");
154
+ writeJson(deps.stdout, await client.listBroadcasts(values));
155
+ return;
156
+ }
157
+ if (action === "audience") {
158
+ const { values } = parseArgs(rest, ACCOUNT, "broadcasts audience");
159
+ writeJson(deps.stdout, await client.getBroadcastAudience(values.account));
160
+ return;
161
+ }
162
+ if (action === "get" || action === "test" || action === "cancel") {
163
+ const { positionals } = parseArgs(rest, {}, `broadcasts ${action}`, 1);
164
+ const id = requiredId("broadcast id", positionals[0]);
165
+ const result = action === "get"
166
+ ? await client.getBroadcast(id)
167
+ : action === "test" ? await client.sendBroadcastTest(id) : await client.cancelBroadcast(id);
168
+ writeJson(deps.stdout, result);
169
+ return;
170
+ }
171
+ if (action === "create") {
172
+ const { values } = parseArgs(rest, { ...ACCOUNT, ...IDEMPOTENCY, ...BROADCAST_FIELDS }, "broadcasts create");
173
+ const payload = await broadcastPayload(values);
174
+ if (!payload.subject || !payload.bodyText) throw new Error("--subject and --body-text (or --file with both) are required");
175
+ writeJson(deps.stdout, await client.createBroadcast(payload, values.account, values.idempotencyKey));
176
+ return;
177
+ }
178
+ if (action === "update") {
179
+ const { positionals, values } = parseArgs(rest, {
180
+ ...BROADCAST_FIELDS,
181
+ "--remove-hero-image": { key: "removeHeroImage", type: "switch" },
182
+ }, "broadcasts update", 1);
183
+ const id = requiredId("broadcast id", positionals[0]);
184
+ if (values.removeHeroImage && values.heroImageUrl !== undefined) {
185
+ throw new Error("--remove-hero-image cannot be combined with --hero-image-url");
186
+ }
187
+ const payload = await broadcastPayload(values);
188
+ if (values.removeHeroImage) payload.heroImageUrl = null;
189
+ requireChanges(payload, "broadcasts update");
190
+ writeJson(deps.stdout, await client.updateBroadcast(id, payload));
191
+ return;
192
+ }
193
+ if (action === "send") {
194
+ const { positionals, values } = parseArgs(rest, {
195
+ "--at": { key: "scheduledAt", type: "iso-date" },
196
+ "--yes": { key: "yes", type: "switch" },
197
+ }, "broadcasts send", 1);
198
+ const id = requiredId("broadcast id", positionals[0]);
199
+ if (!values.yes) {
200
+ throw new Error(
201
+ "Sending a broadcast emails opted-in members and can't be undone once it starts. "
202
+ + "Re-run with --yes to confirm (use `hive3 broadcasts test <id>` first to email only yourself).",
203
+ );
204
+ }
205
+ writeJson(deps.stdout, await client.sendBroadcast(id, pickDefined(values, ["scheduledAt"])));
206
+ return;
207
+ }
208
+ throw new Error(`Unknown broadcasts action: ${action || ""}`.trim());
209
+ }
210
+
211
+ // --- tickets --------------------------------------------------------------
212
+
213
+ async function runTickets(args, deps) {
214
+ const [action, ...rest] = args;
215
+ const client = await authenticatedClient(deps);
216
+ if (action === "list") {
217
+ const { values } = parseArgs(rest, { ...ACCOUNT, ...PAGING }, "tickets list");
218
+ writeJson(deps.stdout, await client.listTickets(values));
219
+ return;
220
+ }
221
+ if (action === "mine") {
222
+ const { values } = parseArgs(rest, PAGING, "tickets mine");
223
+ writeJson(deps.stdout, await client.listMyTickets(values));
224
+ return;
225
+ }
226
+ if (action === "get") {
227
+ const { positionals } = parseArgs(rest, {}, "tickets get", 1);
228
+ writeJson(deps.stdout, await client.getTicket(requiredId("ticket id", positionals[0])));
229
+ return;
230
+ }
231
+ if (action === "update") {
232
+ const { positionals, values } = parseArgs(rest, {
233
+ "--name": { key: "name", type: "string" },
234
+ "--description": { key: "description", type: "string" },
235
+ "--amount": { key: "amount", type: "amount" },
236
+ "--currency": { key: "currency", type: "currency" },
237
+ "--status": { choices: ["active", "inactive"], key: "status", type: "choice" },
238
+ }, "tickets update", 1);
239
+ const id = requiredId("ticket id", positionals[0]);
240
+ requireChanges(values, "tickets update");
241
+ writeJson(deps.stdout, await client.updateTicket(id, values));
242
+ return;
243
+ }
244
+ throw new Error(`Unknown tickets action: ${action || ""}`.trim());
245
+ }
246
+
247
+ // --- AI assistant ---------------------------------------------------------
248
+
249
+ const ASSISTANT_DOCUMENT_TYPES = {
250
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
251
+ ".pdf": "application/pdf",
252
+ ".txt": "text/plain",
253
+ };
254
+
255
+ async function addAssistantDocument(client, rest, deps) {
256
+ const { positionals, values } = parseArgs(rest, {
257
+ ...ACCOUNT,
258
+ ...IDEMPOTENCY,
259
+ "--content-type": { key: "contentType", type: "string" },
260
+ }, "assistant documents add", 1);
261
+ const filePath = requiredId("file", positionals[0]);
262
+ const contentType = values.contentType ?? /** @type {Record<string, string>} */ (ASSISTANT_DOCUMENT_TYPES)[path.extname(filePath).toLowerCase()];
263
+ if (!contentType) throw new Error("Could not infer content type; documents must be PDF, DOCX or plain text (pass --content-type)");
264
+ const fileStat = await stat(filePath);
265
+ const issued = await client.createAssistantUploadUrl(values.account);
266
+ const { uploadUrl, maxBytes } = issued.data;
267
+ if (typeof maxBytes === "number" && fileStat.size > maxBytes) {
268
+ throw new Error(`${path.basename(filePath)} is ${fileStat.size} bytes; assistant documents can be at most ${maxBytes} bytes`);
269
+ }
270
+ const upload = await postFileToUploadUrl(client, deps, uploadUrl, filePath, contentType);
271
+ const storageId = upload.parsed?.data?.storageId ?? upload.parsed?.storageId;
272
+ if (!upload.ok || !storageId) {
273
+ throw new HiveApiError(`Upload failed with status ${upload.status}`, { code: "upload_failed", status: upload.status });
274
+ }
275
+ writeJson(deps.stdout, await client.createAssistantDocument({
276
+ fileName: path.basename(filePath),
277
+ fileSize: fileStat.size,
278
+ mimeType: contentType,
279
+ storageId,
280
+ }, values.account, values.idempotencyKey));
281
+ }
282
+
283
+ async function runAssistant(args, deps) {
284
+ const [action, ...rest] = args;
285
+ const client = await authenticatedClient(deps);
286
+ if (action === "get") {
287
+ const { values } = parseArgs(rest, ACCOUNT, "assistant get");
288
+ writeJson(deps.stdout, await client.getAssistant(values.account));
289
+ return;
290
+ }
291
+ if (action === "update") {
292
+ const { values } = parseArgs(rest, {
293
+ ...ACCOUNT,
294
+ "--name": { key: "name", type: "string" },
295
+ "--description": { key: "description", type: "string" },
296
+ "--avatar-url": { key: "avatarUrl", type: "string" },
297
+ "--visibility": { choices: ["public", "protected", "private"], key: "visibility", type: "choice" },
298
+ }, "assistant update");
299
+ const payload = pickDefined(values, ["name", "description", "avatarUrl", "visibility"]);
300
+ requireChanges(payload, "assistant update");
301
+ writeJson(deps.stdout, await client.updateAssistant(payload, values.account));
302
+ return;
303
+ }
304
+ if (action === "documents") {
305
+ const implicitList = rest[0] === undefined || rest[0].startsWith("--");
306
+ const [documentAction, ...documentArgs] = implicitList ? ["list", ...rest] : rest;
307
+ if (documentAction === "list") {
308
+ const { values } = parseArgs(documentArgs, ACCOUNT, "assistant documents list");
309
+ writeJson(deps.stdout, await client.listAssistantDocuments(values.account));
310
+ return;
311
+ }
312
+ if (documentAction === "add") {
313
+ await addAssistantDocument(client, documentArgs, deps);
314
+ return;
315
+ }
316
+ if (documentAction === "delete") {
317
+ const { positionals, values } = parseArgs(documentArgs, { "--confirm": { key: "confirm", type: "string" } }, "assistant documents delete", 1);
318
+ const id = requiredId("document id", positionals[0]);
319
+ requireExactConfirmation(values, id, "document");
320
+ writeJson(deps.stdout, await client.deleteAssistantDocument(id));
321
+ return;
322
+ }
323
+ throw new Error(`Unknown assistant documents action: ${documentAction}`);
324
+ }
325
+ throw new Error(`Unknown assistant action: ${action || ""}`.trim());
326
+ }
327
+
328
+ // --- credentials ----------------------------------------------------------
329
+
330
+ async function runCredentials(args, deps) {
331
+ const [action, ...rest] = args;
332
+ const client = await authenticatedClient(deps);
333
+ if (action === "list") {
334
+ const { values } = parseArgs(rest, { ...ACCOUNT, ...PAGING }, "credentials list");
335
+ writeJson(deps.stdout, await client.listCredentials(values));
336
+ return;
337
+ }
338
+ if (action === "get") {
339
+ const { positionals } = parseArgs(rest, {}, "credentials get", 1);
340
+ writeJson(deps.stdout, await client.getCredential(requiredId("credential id", positionals[0])));
341
+ return;
342
+ }
343
+ if (action === "mine") {
344
+ parseArgs(rest, {}, "credentials mine");
345
+ writeJson(deps.stdout, await client.listMyCredentials());
346
+ return;
347
+ }
348
+ if (action === "claimable") {
349
+ const { values } = parseArgs(rest, PAGING, "credentials claimable");
350
+ writeJson(deps.stdout, await client.listClaimableCredentials(values));
351
+ return;
352
+ }
353
+ if (action === "award") {
354
+ const { positionals, values } = parseArgs(rest, {
355
+ "--handles": { key: "handles", type: "string" },
356
+ "--yes": { key: "yes", type: "switch" },
357
+ }, "credentials award", 1);
358
+ const id = requiredId("credential id", positionals[0]);
359
+ if (values.handles === undefined) throw new Error("--handles requires a value (comma-separated, up to 50)");
360
+ const handles = values.handles.split(",").map((handle) => handle.trim()).filter(Boolean);
361
+ if (handles.length < 1 || handles.length > 50) throw new Error("--handles must list between 1 and 50 handles");
362
+ if (!values.yes) {
363
+ throw new Error(
364
+ `Awarding a credential gives it to ${handles.length} account(s) and can't be undone through the CLI. Re-run with --yes to confirm.`,
365
+ );
366
+ }
367
+ writeJson(deps.stdout, await client.awardCredential(id, handles));
368
+ return;
369
+ }
370
+ throw new Error(`Unknown credentials action: ${action || ""}`.trim());
371
+ }
372
+
373
+ /**
374
+ * Dispatch for the search, broadcasts, tickets, assistant and credentials commands.
375
+ * @returns {Promise<boolean>} true when the command belonged to this module
376
+ */
377
+ export async function runAreaCommand(command, args, deps) {
378
+ if (command === "search") await runSearch(args, deps);
379
+ else if (command === "broadcasts") await runBroadcasts(args, deps);
380
+ else if (command === "tickets") await runTickets(args, deps);
381
+ else if (command === "assistant") await runAssistant(args, deps);
382
+ else if (command === "credentials") await runCredentials(args, deps);
383
+ else return false;
384
+ return true;
385
+ }