@rehpic/vcli 0.1.0-beta.5.1

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/dist/index.js ADDED
@@ -0,0 +1,2042 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../../src/cli/index.ts
4
+ import { readFile as readFile2 } from "fs/promises";
5
+ import { extname } from "path";
6
+ import { config as loadEnv } from "dotenv";
7
+ import { Command } from "commander";
8
+ import { makeFunctionReference } from "convex/server";
9
+
10
+ // ../../convex/_generated/api.js
11
+ import { anyApi, componentsGeneric } from "convex/server";
12
+ var api = anyApi;
13
+ var components = componentsGeneric();
14
+
15
+ // ../../src/cli/auth.ts
16
+ import { isCancel, password as passwordPrompt, text } from "@clack/prompts";
17
+ function buildUrl(appUrl, pathname) {
18
+ return new URL(pathname, appUrl).toString();
19
+ }
20
+ function cookieHeader(cookies) {
21
+ return Object.entries(cookies).map(([name, value]) => `${name}=${value}`).join("; ");
22
+ }
23
+ function splitSetCookieHeader(value) {
24
+ return value.split(/,(?=[^;,]+=)/g);
25
+ }
26
+ function applySetCookieHeaders(session, response) {
27
+ const nextCookies = { ...session.cookies };
28
+ const rawSetCookies = response.headers.getSetCookie?.() ?? (response.headers.get("set-cookie") ? splitSetCookieHeader(response.headers.get("set-cookie")) : []);
29
+ for (const rawCookie of rawSetCookies) {
30
+ const [cookiePart, ...attributeParts] = rawCookie.split(";");
31
+ const separatorIndex = cookiePart.indexOf("=");
32
+ if (separatorIndex <= 0) {
33
+ continue;
34
+ }
35
+ const name = cookiePart.slice(0, separatorIndex).trim();
36
+ const value = cookiePart.slice(separatorIndex + 1).trim();
37
+ const attributes = attributeParts.map((part) => part.trim().toLowerCase());
38
+ const maxAge = attributes.find((part) => part.startsWith("max-age="));
39
+ const expires = attributes.find((part) => part.startsWith("expires="));
40
+ const expired = value.length === 0 || maxAge === "max-age=0" || (expires ? Number.isFinite(Date.parse(expires.slice(8))) && Date.parse(expires.slice(8)) <= Date.now() : false);
41
+ if (expired) {
42
+ delete nextCookies[name];
43
+ } else {
44
+ nextCookies[name] = value;
45
+ }
46
+ }
47
+ return {
48
+ ...session,
49
+ cookies: nextCookies
50
+ };
51
+ }
52
+ async function authRequest(session, appUrl, pathname, init = {}) {
53
+ const headers = new Headers(init.headers);
54
+ const origin = new URL(appUrl).origin;
55
+ if (Object.keys(session.cookies).length > 0) {
56
+ headers.set("cookie", cookieHeader(session.cookies));
57
+ }
58
+ if (!headers.has("origin")) {
59
+ headers.set("origin", origin);
60
+ }
61
+ if (!headers.has("referer")) {
62
+ headers.set("referer", `${origin}/`);
63
+ }
64
+ if (init.body && !headers.has("content-type")) {
65
+ headers.set("content-type", "application/json");
66
+ }
67
+ const response = await fetch(buildUrl(appUrl, pathname), {
68
+ ...init,
69
+ headers,
70
+ redirect: "manual"
71
+ });
72
+ const nextSession = applySetCookieHeaders(session, response);
73
+ return { response, session: nextSession };
74
+ }
75
+ async function parseError(response) {
76
+ try {
77
+ const data = await response.json();
78
+ return data.error?.message ?? `Request failed with HTTP ${response.status}`;
79
+ } catch {
80
+ return `Request failed with HTTP ${response.status}`;
81
+ }
82
+ }
83
+ async function loginWithPassword(session, appUrl, identifier, password) {
84
+ const pathname = identifier.includes("@") ? "/api/auth/sign-in/email" : "/api/auth/sign-in/username";
85
+ const body = identifier.includes("@") ? { email: identifier, password } : { username: identifier, password };
86
+ const { response, session: nextSession } = await authRequest(
87
+ session,
88
+ appUrl,
89
+ pathname,
90
+ {
91
+ method: "POST",
92
+ body: JSON.stringify(body)
93
+ }
94
+ );
95
+ if (!response.ok) {
96
+ throw new Error(await parseError(response));
97
+ }
98
+ return nextSession;
99
+ }
100
+ async function signUpWithEmail(session, appUrl, email, username, password) {
101
+ const { response, session: nextSession } = await authRequest(
102
+ session,
103
+ appUrl,
104
+ "/api/auth/sign-up/email",
105
+ {
106
+ method: "POST",
107
+ body: JSON.stringify({
108
+ email,
109
+ password,
110
+ name: username,
111
+ username
112
+ })
113
+ }
114
+ );
115
+ if (!response.ok) {
116
+ throw new Error(await parseError(response));
117
+ }
118
+ return nextSession;
119
+ }
120
+ async function logout(session, appUrl) {
121
+ const { response } = await authRequest(
122
+ session,
123
+ appUrl,
124
+ "/api/auth/sign-out",
125
+ {
126
+ method: "POST",
127
+ body: JSON.stringify({})
128
+ }
129
+ );
130
+ if (!response.ok) {
131
+ throw new Error(await parseError(response));
132
+ }
133
+ }
134
+ async function fetchAuthSession(session, appUrl) {
135
+ const { response, session: nextSession } = await authRequest(
136
+ session,
137
+ appUrl,
138
+ "/api/auth/get-session",
139
+ {
140
+ method: "GET"
141
+ }
142
+ );
143
+ if (!response.ok) {
144
+ throw new Error(await parseError(response));
145
+ }
146
+ const data = await response.json();
147
+ return {
148
+ session: nextSession,
149
+ user: data.user ?? null
150
+ };
151
+ }
152
+ async function fetchConvexToken(session, appUrl) {
153
+ const { response, session: nextSession } = await authRequest(
154
+ session,
155
+ appUrl,
156
+ "/api/auth/convex/token",
157
+ {
158
+ method: "GET"
159
+ }
160
+ );
161
+ if (!response.ok) {
162
+ throw new Error(await parseError(response));
163
+ }
164
+ const data = await response.json();
165
+ if (!data.token) {
166
+ throw new Error("Missing Convex token");
167
+ }
168
+ return {
169
+ session: nextSession,
170
+ token: data.token
171
+ };
172
+ }
173
+ async function prompt(question) {
174
+ const value = await text({
175
+ message: question.replace(/:\s*$/, "")
176
+ });
177
+ if (isCancel(value)) {
178
+ throw new Error("Canceled");
179
+ }
180
+ return String(value).trim();
181
+ }
182
+ async function promptSecret(question) {
183
+ const value = await passwordPrompt({
184
+ message: question.replace(/:\s*$/, ""),
185
+ mask: "*"
186
+ });
187
+ if (isCancel(value)) {
188
+ throw new Error("Canceled");
189
+ }
190
+ return String(value);
191
+ }
192
+
193
+ // ../../src/cli/convex.ts
194
+ import { ConvexHttpClient } from "convex/browser";
195
+ async function createConvexClient(session, appUrl, convexUrl) {
196
+ const { token } = await fetchConvexToken(session, appUrl);
197
+ const client = new ConvexHttpClient(convexUrl);
198
+ client.setAuth(token);
199
+ return client;
200
+ }
201
+ async function runQuery(client, ref, ...args) {
202
+ return await client.query(ref, ...args);
203
+ }
204
+ async function runMutation(client, ref, ...args) {
205
+ return await client.mutation(ref, ...args);
206
+ }
207
+ async function runAction(client, ref, ...args) {
208
+ return await client.action(ref, ...args);
209
+ }
210
+
211
+ // ../../src/cli/output.ts
212
+ function simplify(value) {
213
+ if (value === null || value === void 0) {
214
+ return value;
215
+ }
216
+ if (Array.isArray(value)) {
217
+ if (value.length === 0) {
218
+ return [];
219
+ }
220
+ if (value.every((item) => typeof item !== "object" || item === null)) {
221
+ return value.join(", ");
222
+ }
223
+ return JSON.stringify(value);
224
+ }
225
+ if (typeof value === "object") {
226
+ return JSON.stringify(value);
227
+ }
228
+ return value;
229
+ }
230
+ function printOutput(data, json = false) {
231
+ if (json) {
232
+ console.log(JSON.stringify(data, null, 2));
233
+ return;
234
+ }
235
+ if (Array.isArray(data)) {
236
+ if (data.length === 0) {
237
+ console.log("No results.");
238
+ return;
239
+ }
240
+ if (data.every((item) => typeof item === "object" && item !== null)) {
241
+ console.table(
242
+ data.map(
243
+ (item) => Object.fromEntries(
244
+ Object.entries(item).map(([key, value]) => [key, simplify(value)])
245
+ )
246
+ )
247
+ );
248
+ return;
249
+ }
250
+ }
251
+ if (typeof data === "object" && data !== null) {
252
+ console.dir(data, { depth: null, colors: true });
253
+ return;
254
+ }
255
+ console.log(String(data));
256
+ }
257
+
258
+ // ../../src/cli/session.ts
259
+ import { mkdir, readFile, rm, writeFile } from "fs/promises";
260
+ import { homedir } from "os";
261
+ import path from "path";
262
+ var SESSION_ROOT = path.join(homedir(), ".vector");
263
+ function getSessionPath(profile = "default") {
264
+ return path.join(SESSION_ROOT, `cli-${profile}.json`);
265
+ }
266
+ async function readSession(profile = "default") {
267
+ try {
268
+ const raw = await readFile(getSessionPath(profile), "utf8");
269
+ const parsed = JSON.parse(raw);
270
+ return {
271
+ version: 1,
272
+ cookies: {},
273
+ ...parsed
274
+ };
275
+ } catch {
276
+ return null;
277
+ }
278
+ }
279
+ async function writeSession(session, profile = "default") {
280
+ await mkdir(SESSION_ROOT, { recursive: true });
281
+ await writeFile(
282
+ getSessionPath(profile),
283
+ `${JSON.stringify(session, null, 2)}
284
+ `,
285
+ "utf8"
286
+ );
287
+ }
288
+ async function clearSession(profile = "default") {
289
+ await rm(getSessionPath(profile), { force: true });
290
+ }
291
+ function createEmptySession() {
292
+ return {
293
+ version: 1,
294
+ cookies: {}
295
+ };
296
+ }
297
+
298
+ // ../../src/cli/index.ts
299
+ loadEnv({ path: ".env.local", override: false });
300
+ loadEnv({ path: ".env", override: false });
301
+ var cliApi = {
302
+ listWorkspaceReferenceData: makeFunctionReference(
303
+ "cli:listWorkspaceReferenceData"
304
+ ),
305
+ searchIcons: makeFunctionReference("cli:searchIcons"),
306
+ listDocuments: makeFunctionReference("cli:listDocuments"),
307
+ getDocument: makeFunctionReference("cli:getDocument"),
308
+ createDocument: makeFunctionReference("cli:createDocument"),
309
+ updateDocument: makeFunctionReference("cli:updateDocument"),
310
+ deleteDocument: makeFunctionReference("cli:deleteDocument"),
311
+ moveDocumentToFolder: makeFunctionReference(
312
+ "cli:moveDocumentToFolder"
313
+ ),
314
+ listIssues: makeFunctionReference("cli:listIssues"),
315
+ getIssue: makeFunctionReference("cli:getIssue"),
316
+ createIssue: makeFunctionReference("cli:createIssue"),
317
+ updateIssue: makeFunctionReference("cli:updateIssue"),
318
+ deleteIssue: makeFunctionReference("cli:deleteIssue"),
319
+ assignIssue: makeFunctionReference("cli:assignIssue"),
320
+ unassignIssue: makeFunctionReference("cli:unassignIssue"),
321
+ listProjects: makeFunctionReference("cli:listProjects"),
322
+ getProject: makeFunctionReference("cli:getProject"),
323
+ createProject: makeFunctionReference("cli:createProject"),
324
+ updateProject: makeFunctionReference("cli:updateProject"),
325
+ deleteProject: makeFunctionReference("cli:deleteProject"),
326
+ addProjectMember: makeFunctionReference("cli:addProjectMember"),
327
+ removeProjectMember: makeFunctionReference(
328
+ "cli:removeProjectMember"
329
+ ),
330
+ changeProjectLead: makeFunctionReference("cli:changeProjectLead"),
331
+ listTeams: makeFunctionReference("cli:listTeams"),
332
+ getTeam: makeFunctionReference("cli:getTeam"),
333
+ createTeam: makeFunctionReference("cli:createTeam"),
334
+ updateTeam: makeFunctionReference("cli:updateTeam"),
335
+ deleteTeam: makeFunctionReference("cli:deleteTeam"),
336
+ addTeamMember: makeFunctionReference("cli:addTeamMember"),
337
+ removeTeamMember: makeFunctionReference("cli:removeTeamMember"),
338
+ changeTeamLead: makeFunctionReference("cli:changeTeamLead"),
339
+ listFolders: makeFunctionReference("cli:listFolders"),
340
+ createFolder: makeFunctionReference("cli:createFolder"),
341
+ updateFolder: makeFunctionReference("cli:updateFolder"),
342
+ deleteFolder: makeFunctionReference("cli:deleteFolder")
343
+ };
344
+ var rolesApi = api.roles.index;
345
+ var ISSUE_STATE_TYPES = [
346
+ "backlog",
347
+ "todo",
348
+ "in_progress",
349
+ "done",
350
+ "canceled"
351
+ ];
352
+ var PROJECT_STATUS_TYPES = [
353
+ "backlog",
354
+ "planned",
355
+ "in_progress",
356
+ "completed",
357
+ "canceled"
358
+ ];
359
+ var NOTIFICATION_CATEGORIES = [
360
+ "invites",
361
+ "assignments",
362
+ "mentions",
363
+ "comments"
364
+ ];
365
+ function requiredString(value, label) {
366
+ if (!value?.trim()) {
367
+ throw new Error(`${label} is required`);
368
+ }
369
+ return value.trim();
370
+ }
371
+ function optionalNumber(value, label) {
372
+ if (value === void 0) {
373
+ return void 0;
374
+ }
375
+ const parsed = Number(value);
376
+ if (!Number.isFinite(parsed)) {
377
+ throw new Error(`${label} must be a valid number`);
378
+ }
379
+ return parsed;
380
+ }
381
+ function requiredNumber(value, label) {
382
+ const parsed = optionalNumber(value, label);
383
+ if (parsed === void 0) {
384
+ throw new Error(`${label} is required`);
385
+ }
386
+ return parsed;
387
+ }
388
+ function parseBoolean(value, label) {
389
+ const normalized = value.trim().toLowerCase();
390
+ if (normalized === "true") return true;
391
+ if (normalized === "false") return false;
392
+ throw new Error(`${label} must be "true" or "false"`);
393
+ }
394
+ function parseList(value) {
395
+ if (!value) return [];
396
+ return value.split(",").map((item) => item.trim()).filter(Boolean);
397
+ }
398
+ function buildPaginationOptions(limit, cursor) {
399
+ return {
400
+ cursor: cursor ?? null,
401
+ numItems: optionalNumber(limit, "limit") ?? 20
402
+ };
403
+ }
404
+ function normalizeMatch(value) {
405
+ return value?.trim().toLowerCase();
406
+ }
407
+ async function getRuntime(command) {
408
+ const options = command.optsWithGlobals();
409
+ const profile = options.profile ?? "default";
410
+ const session = await readSession(profile);
411
+ const appUrlSource = options.appUrl ?? session?.appUrl ?? process.env.NEXT_PUBLIC_APP_URL;
412
+ const appUrl = requiredString(appUrlSource, "app URL");
413
+ const convexUrl = options.convexUrl ?? session?.convexUrl ?? process.env.NEXT_PUBLIC_CONVEX_URL ?? process.env.CONVEX_URL ?? "http://127.0.0.1:3210";
414
+ return {
415
+ appUrl,
416
+ convexUrl,
417
+ json: Boolean(options.json),
418
+ org: options.org ?? session?.activeOrgSlug,
419
+ profile,
420
+ session
421
+ };
422
+ }
423
+ function requireSession(runtime) {
424
+ if (!runtime.session || Object.keys(runtime.session.cookies).length === 0) {
425
+ throw new Error("Not logged in. Run `vcli auth login` first.");
426
+ }
427
+ return runtime.session;
428
+ }
429
+ function requireOrg(runtime, explicit) {
430
+ const orgSlug = explicit ?? runtime.org;
431
+ if (!orgSlug) {
432
+ throw new Error(
433
+ "Organization slug is required. Pass `--org <slug>` or run `vcli org use <slug>`."
434
+ );
435
+ }
436
+ return orgSlug;
437
+ }
438
+ async function getClient(command) {
439
+ const runtime = await getRuntime(command);
440
+ const session = requireSession(runtime);
441
+ const client = await createConvexClient(
442
+ session,
443
+ runtime.appUrl,
444
+ runtime.convexUrl
445
+ );
446
+ return { client, runtime, session };
447
+ }
448
+ async function resolveMemberId(client, orgSlug, ref) {
449
+ const members = await runQuery(
450
+ client,
451
+ api.organizations.queries.listMembers,
452
+ {
453
+ orgSlug
454
+ }
455
+ );
456
+ const needle = normalizeMatch(ref);
457
+ const matches = members.filter((member) => {
458
+ const user = member.user;
459
+ if (!user) return false;
460
+ return normalizeMatch(String(user._id)) === needle || normalizeMatch(user.email) === needle || normalizeMatch(user.name) === needle || normalizeMatch(user.username) === needle;
461
+ });
462
+ if (matches.length === 0) {
463
+ throw new Error(`No member matched "${ref}"`);
464
+ }
465
+ if (matches.length > 1) {
466
+ throw new Error(`Multiple members matched "${ref}"`);
467
+ }
468
+ return matches[0].user._id;
469
+ }
470
+ async function resolveRoleId(client, orgSlug, ref) {
471
+ const roles = await runQuery(client, rolesApi.list, { orgSlug });
472
+ const needle = normalizeMatch(ref);
473
+ const matches = roles.filter((role) => {
474
+ const candidate = role;
475
+ return normalizeMatch(String(candidate._id)) === needle || normalizeMatch(candidate.name) === needle || normalizeMatch(candidate.key) === needle;
476
+ });
477
+ if (matches.length === 0) {
478
+ throw new Error(`No role matched "${ref}"`);
479
+ }
480
+ if (matches.length > 1) {
481
+ throw new Error(`Multiple roles matched "${ref}"`);
482
+ }
483
+ return matches[0]._id;
484
+ }
485
+ function parsePermissions(value) {
486
+ return value.split(",").map((permission) => permission.trim()).filter(Boolean);
487
+ }
488
+ function nullableOption(value, clear = false) {
489
+ if (clear) return null;
490
+ return value;
491
+ }
492
+ function mimeTypeForFile(filePath) {
493
+ switch (extname(filePath).toLowerCase()) {
494
+ case ".png":
495
+ return "image/png";
496
+ case ".jpg":
497
+ case ".jpeg":
498
+ return "image/jpeg";
499
+ case ".webp":
500
+ return "image/webp";
501
+ case ".gif":
502
+ return "image/gif";
503
+ case ".svg":
504
+ return "image/svg+xml";
505
+ default:
506
+ return "application/octet-stream";
507
+ }
508
+ }
509
+ async function uploadFile(uploadUrl, filePath) {
510
+ const body = await readFile2(filePath);
511
+ const response = await fetch(uploadUrl, {
512
+ method: "POST",
513
+ headers: {
514
+ "Content-Type": mimeTypeForFile(filePath)
515
+ },
516
+ body
517
+ });
518
+ if (!response.ok) {
519
+ throw new Error(`Upload failed with HTTP ${response.status}`);
520
+ }
521
+ const data = await response.json();
522
+ if (!data.storageId) {
523
+ throw new Error("Upload response did not include a storageId");
524
+ }
525
+ return data.storageId;
526
+ }
527
+ async function resolveTeamId(client, orgSlug, teamKey) {
528
+ if (!teamKey) {
529
+ return void 0;
530
+ }
531
+ const team = await runAction(client, cliApi.getTeam, { orgSlug, teamKey });
532
+ return team.id;
533
+ }
534
+ async function resolveProjectId(client, orgSlug, projectKey) {
535
+ if (!projectKey) {
536
+ return void 0;
537
+ }
538
+ const project = await runAction(client, cliApi.getProject, {
539
+ orgSlug,
540
+ projectKey
541
+ });
542
+ return project.id;
543
+ }
544
+ async function resolveIssueId(client, orgSlug, issueKey) {
545
+ const issue = await runAction(client, cliApi.getIssue, { orgSlug, issueKey });
546
+ return issue.id;
547
+ }
548
+ async function resolveDocumentId(client, orgSlug, documentId) {
549
+ const document = await runAction(client, cliApi.getDocument, {
550
+ orgSlug,
551
+ documentId
552
+ });
553
+ return document.id;
554
+ }
555
+ async function resolveIssueStateId(client, orgSlug, ref) {
556
+ const states = await runQuery(
557
+ client,
558
+ api.organizations.queries.listIssueStates,
559
+ {
560
+ orgSlug
561
+ }
562
+ );
563
+ const needle = normalizeMatch(ref);
564
+ const match = states.find((state) => {
565
+ return normalizeMatch(String(state._id)) === needle || normalizeMatch(state.name) === needle || normalizeMatch(state.type) === needle;
566
+ });
567
+ if (!match) {
568
+ throw new Error(`No issue state matched "${ref}"`);
569
+ }
570
+ return match._id;
571
+ }
572
+ async function resolveIssuePriorityId(client, orgSlug, ref) {
573
+ const priorities = await runQuery(
574
+ client,
575
+ api.organizations.queries.listIssuePriorities,
576
+ { orgSlug }
577
+ );
578
+ const needle = normalizeMatch(ref);
579
+ const match = priorities.find((priority) => {
580
+ return normalizeMatch(String(priority._id)) === needle || normalizeMatch(priority.name) === needle;
581
+ });
582
+ if (!match) {
583
+ throw new Error(`No issue priority matched "${ref}"`);
584
+ }
585
+ return match._id;
586
+ }
587
+ async function resolveProjectStatusId(client, orgSlug, ref) {
588
+ const statuses = await runQuery(
589
+ client,
590
+ api.organizations.queries.listProjectStatuses,
591
+ { orgSlug }
592
+ );
593
+ const needle = normalizeMatch(ref);
594
+ const match = statuses.find((status) => {
595
+ return normalizeMatch(String(status._id)) === needle || normalizeMatch(status.name) === needle || normalizeMatch(status.type) === needle;
596
+ });
597
+ if (!match) {
598
+ throw new Error(`No project status matched "${ref}"`);
599
+ }
600
+ return match._id;
601
+ }
602
+ async function parseEstimatedTimes(client, orgSlug, value) {
603
+ const entries = parseList(value);
604
+ const estimatedTimes = {};
605
+ for (const entry of entries) {
606
+ const separatorIndex = entry.indexOf("=");
607
+ if (separatorIndex <= 0) {
608
+ throw new Error(
609
+ 'estimated times must use the format "state=hours,state=hours"'
610
+ );
611
+ }
612
+ const stateRef = entry.slice(0, separatorIndex).trim();
613
+ const hours = Number(entry.slice(separatorIndex + 1).trim());
614
+ if (!Number.isFinite(hours)) {
615
+ throw new Error(`Invalid estimate for "${stateRef}"`);
616
+ }
617
+ const stateId = await resolveIssueStateId(client, orgSlug, stateRef);
618
+ estimatedTimes[String(stateId)] = hours;
619
+ }
620
+ return estimatedTimes;
621
+ }
622
+ var program = new Command();
623
+ program.name("vcli").description("Vector CLI").showHelpAfterError().option(
624
+ "--app-url <url>",
625
+ "Vector app URL. Required unless saved in the profile or NEXT_PUBLIC_APP_URL is set."
626
+ ).option("--convex-url <url>", "Convex deployment URL").option("--org <slug>", "Organization slug override").option("--profile <name>", "CLI profile name", "default").option("--json", "Output JSON");
627
+ var authCommand = program.command("auth").description("Authentication");
628
+ authCommand.command("signup").option("--email <email>", "Email address").option("--username <username>", "Username").option("--password <password>", "Password").action(async (options, command) => {
629
+ const runtime = await getRuntime(command);
630
+ const email = requiredString(
631
+ options.email?.trim() || await prompt("Email: "),
632
+ "email"
633
+ ).toLowerCase();
634
+ const username = requiredString(
635
+ options.username?.trim() || await prompt("Username: "),
636
+ "username"
637
+ );
638
+ const password = options.password?.trim() || await promptSecret("Password: ");
639
+ let session = createEmptySession();
640
+ session.appUrl = runtime.appUrl;
641
+ session.convexUrl = runtime.convexUrl;
642
+ session = await signUpWithEmail(
643
+ session,
644
+ runtime.appUrl,
645
+ email,
646
+ username,
647
+ password
648
+ );
649
+ const authState = await fetchAuthSession(session, runtime.appUrl);
650
+ session = authState.session;
651
+ const client = await createConvexClient(
652
+ session,
653
+ runtime.appUrl,
654
+ runtime.convexUrl
655
+ );
656
+ const orgs = await runQuery(client, api.users.getOrganizations, {});
657
+ session.activeOrgSlug = orgs[0]?.slug ?? session.activeOrgSlug;
658
+ await writeSession(session, runtime.profile);
659
+ printOutput(
660
+ {
661
+ signedUpAs: authState.user?.email ?? authState.user?.username ?? authState.user?.name,
662
+ activeOrgSlug: session.activeOrgSlug ?? null
663
+ },
664
+ runtime.json
665
+ );
666
+ });
667
+ authCommand.command("login [identifier]").option("--password <password>", "Password").action(async (identifier, options, command) => {
668
+ const runtime = await getRuntime(command);
669
+ const loginId = identifier?.trim() || await prompt("Email or username: ");
670
+ const password = options.password?.trim() || await promptSecret("Password: ");
671
+ let session = createEmptySession();
672
+ session.appUrl = runtime.appUrl;
673
+ session.convexUrl = runtime.convexUrl;
674
+ session = await loginWithPassword(
675
+ session,
676
+ runtime.appUrl,
677
+ loginId,
678
+ password
679
+ );
680
+ const authState = await fetchAuthSession(session, runtime.appUrl);
681
+ session = authState.session;
682
+ const client = await createConvexClient(
683
+ session,
684
+ runtime.appUrl,
685
+ runtime.convexUrl
686
+ );
687
+ const orgs = await runQuery(client, api.users.getOrganizations, {});
688
+ session.activeOrgSlug = orgs[0]?.slug ?? session.activeOrgSlug;
689
+ await writeSession(session, runtime.profile);
690
+ printOutput(
691
+ {
692
+ loggedInAs: authState.user?.email ?? authState.user?.username ?? authState.user?.name,
693
+ activeOrgSlug: session.activeOrgSlug ?? null
694
+ },
695
+ runtime.json
696
+ );
697
+ });
698
+ authCommand.command("logout").action(async (_options, command) => {
699
+ const runtime = await getRuntime(command);
700
+ const session = requireSession(runtime);
701
+ await logout(session, runtime.appUrl);
702
+ await clearSession(runtime.profile);
703
+ printOutput({ success: true }, runtime.json);
704
+ });
705
+ authCommand.command("whoami").action(async (_options, command) => {
706
+ const { client, runtime } = await getClient(command);
707
+ const [user, orgs] = await Promise.all([
708
+ runQuery(client, api.users.getCurrentUser, {}),
709
+ runQuery(client, api.users.getOrganizations, {})
710
+ ]);
711
+ printOutput(
712
+ {
713
+ user,
714
+ organizations: orgs,
715
+ activeOrgSlug: runtime.org ?? null
716
+ },
717
+ runtime.json
718
+ );
719
+ });
720
+ var orgCommand = program.command("org").description("Organizations");
721
+ orgCommand.command("list").action(async (_options, command) => {
722
+ const { client, runtime } = await getClient(command);
723
+ const orgs = await runQuery(client, api.users.getOrganizations, {});
724
+ printOutput(orgs, runtime.json);
725
+ });
726
+ orgCommand.command("current").action(async (_options, command) => {
727
+ const runtime = await getRuntime(command);
728
+ printOutput({ activeOrgSlug: runtime.org ?? null }, runtime.json);
729
+ });
730
+ orgCommand.command("use <slug>").action(async (slug, _options, command) => {
731
+ const runtime = await getRuntime(command);
732
+ const session = requireSession(runtime);
733
+ session.activeOrgSlug = slug;
734
+ session.appUrl = runtime.appUrl;
735
+ session.convexUrl = runtime.convexUrl;
736
+ await writeSession(session, runtime.profile);
737
+ printOutput({ activeOrgSlug: slug }, runtime.json);
738
+ });
739
+ orgCommand.command("create").requiredOption("--name <name>").requiredOption("--slug <slug>").action(async (options, command) => {
740
+ const { client, runtime, session } = await getClient(command);
741
+ const result = await runMutation(
742
+ client,
743
+ api.organizations.mutations.create,
744
+ {
745
+ data: {
746
+ name: options.name,
747
+ slug: options.slug
748
+ }
749
+ }
750
+ );
751
+ if (session) {
752
+ session.activeOrgSlug = options.slug;
753
+ session.appUrl = runtime.appUrl;
754
+ session.convexUrl = runtime.convexUrl;
755
+ await writeSession(session, runtime.profile);
756
+ }
757
+ printOutput(result, runtime.json);
758
+ });
759
+ orgCommand.command("update [slug]").option("--name <name>").option("--new-slug <slug>").action(async (slug, options, command) => {
760
+ const { client, runtime, session } = await getClient(command);
761
+ const orgSlug = requireOrg(runtime, slug);
762
+ const result = await runMutation(
763
+ client,
764
+ api.organizations.mutations.update,
765
+ {
766
+ orgSlug,
767
+ data: {
768
+ ...options.name ? { name: options.name } : {},
769
+ ...options.newSlug ? { slug: options.newSlug } : {}
770
+ }
771
+ }
772
+ );
773
+ if (session && options.newSlug && session.activeOrgSlug === orgSlug) {
774
+ session.activeOrgSlug = options.newSlug;
775
+ await writeSession(session, runtime.profile);
776
+ }
777
+ printOutput(result, runtime.json);
778
+ });
779
+ orgCommand.command("stats [slug]").action(async (slug, _options, command) => {
780
+ const { client, runtime } = await getClient(command);
781
+ const orgSlug = requireOrg(runtime, slug);
782
+ const result = await runQuery(
783
+ client,
784
+ api.organizations.queries.getOrganizationStats,
785
+ { orgSlug }
786
+ );
787
+ printOutput(result, runtime.json);
788
+ });
789
+ orgCommand.command("logo [slug]").option("--file <path>").option("--remove").action(async (slug, options, command) => {
790
+ const { client, runtime } = await getClient(command);
791
+ const orgSlug = requireOrg(runtime, slug);
792
+ if (options.remove) {
793
+ throw new Error(
794
+ "Organization logo removal is not exposed by the current backend API."
795
+ );
796
+ }
797
+ const filePath = requiredString(options.file, "file");
798
+ const uploadUrl = await runMutation(
799
+ client,
800
+ api.organizations.mutations.generateLogoUploadUrl,
801
+ { orgSlug }
802
+ );
803
+ const storageId = await uploadFile(uploadUrl, filePath);
804
+ const result = await runMutation(
805
+ client,
806
+ api.organizations.mutations.updateLogoWithStorageId,
807
+ {
808
+ orgSlug,
809
+ storageId
810
+ }
811
+ );
812
+ printOutput(
813
+ { ...result ?? { success: true }, storageId, orgSlug },
814
+ runtime.json
815
+ );
816
+ });
817
+ orgCommand.command("members [slug]").action(async (slug, _options, command) => {
818
+ const { client, runtime } = await getClient(command);
819
+ const orgSlug = requireOrg(runtime, slug);
820
+ const members = await runQuery(
821
+ client,
822
+ api.organizations.queries.listMembersWithRoles,
823
+ {
824
+ orgSlug
825
+ }
826
+ );
827
+ printOutput(members, runtime.json);
828
+ });
829
+ orgCommand.command("invites [slug]").action(async (slug, _options, command) => {
830
+ const { client, runtime } = await getClient(command);
831
+ const orgSlug = requireOrg(runtime, slug);
832
+ const invites = await runQuery(
833
+ client,
834
+ api.organizations.queries.listInvites,
835
+ {
836
+ orgSlug
837
+ }
838
+ );
839
+ printOutput(invites, runtime.json);
840
+ });
841
+ orgCommand.command("invite [slug]").requiredOption("--email <email>").option("--role <role>", "member or admin", "member").action(async (slug, options, command) => {
842
+ const { client, runtime } = await getClient(command);
843
+ const orgSlug = requireOrg(runtime, slug);
844
+ const result = await runMutation(
845
+ client,
846
+ api.organizations.mutations.invite,
847
+ {
848
+ orgSlug,
849
+ email: options.email,
850
+ role: options.role
851
+ }
852
+ );
853
+ printOutput(result, runtime.json);
854
+ });
855
+ orgCommand.command("member-role <member>").requiredOption("--role <role>", "member or admin").action(async (member, options, command) => {
856
+ const { client, runtime } = await getClient(command);
857
+ const orgSlug = requireOrg(runtime);
858
+ const userId = await resolveMemberId(client, orgSlug, member);
859
+ const result = await runMutation(
860
+ client,
861
+ api.organizations.mutations.updateMemberRole,
862
+ {
863
+ orgSlug,
864
+ userId,
865
+ role: options.role
866
+ }
867
+ );
868
+ printOutput(result, runtime.json);
869
+ });
870
+ orgCommand.command("remove-member <member>").action(async (member, _options, command) => {
871
+ const { client, runtime } = await getClient(command);
872
+ const orgSlug = requireOrg(runtime);
873
+ const userId = await resolveMemberId(client, orgSlug, member);
874
+ const result = await runMutation(
875
+ client,
876
+ api.organizations.mutations.removeMember,
877
+ {
878
+ orgSlug,
879
+ userId
880
+ }
881
+ );
882
+ printOutput(result ?? { success: true }, runtime.json);
883
+ });
884
+ orgCommand.command("revoke-invite <inviteId>").action(async (inviteId, _options, command) => {
885
+ const { client, runtime } = await getClient(command);
886
+ const result = await runMutation(
887
+ client,
888
+ api.organizations.mutations.revokeInvite,
889
+ {
890
+ inviteId
891
+ }
892
+ );
893
+ printOutput(result ?? { success: true }, runtime.json);
894
+ });
895
+ var roleCommand = program.command("role").description("Organization roles");
896
+ roleCommand.command("list [slug]").action(async (slug, _options, command) => {
897
+ const { client, runtime } = await getClient(command);
898
+ const orgSlug = requireOrg(runtime, slug);
899
+ const roles = await runQuery(client, rolesApi.list, { orgSlug });
900
+ printOutput(roles, runtime.json);
901
+ });
902
+ roleCommand.command("get <role>").action(async (role, _options, command) => {
903
+ const { client, runtime } = await getClient(command);
904
+ const orgSlug = requireOrg(runtime);
905
+ const roleId = await resolveRoleId(client, orgSlug, role);
906
+ const [summary, permissions] = await Promise.all([
907
+ runQuery(client, rolesApi.get, { orgSlug, roleId }),
908
+ runQuery(client, rolesApi.getPermissions, { roleId })
909
+ ]);
910
+ printOutput({ summary, permissions }, runtime.json);
911
+ });
912
+ roleCommand.command("create").requiredOption("--name <name>").requiredOption("--permissions <permissions>", "Comma-separated permissions").option("--description <description>").action(async (options, command) => {
913
+ const { client, runtime } = await getClient(command);
914
+ const orgSlug = requireOrg(runtime);
915
+ const result = await runMutation(client, rolesApi.create, {
916
+ orgSlug,
917
+ name: options.name,
918
+ description: options.description,
919
+ permissions: parsePermissions(options.permissions)
920
+ });
921
+ printOutput({ roleId: result }, runtime.json);
922
+ });
923
+ roleCommand.command("update <role>").requiredOption("--name <name>").requiredOption("--permissions <permissions>", "Comma-separated permissions").option("--description <description>").action(async (role, options, command) => {
924
+ const { client, runtime } = await getClient(command);
925
+ const orgSlug = requireOrg(runtime);
926
+ const roleId = await resolveRoleId(client, orgSlug, role);
927
+ const result = await runMutation(client, rolesApi.update, {
928
+ orgSlug,
929
+ roleId,
930
+ name: options.name,
931
+ description: options.description,
932
+ permissions: parsePermissions(options.permissions)
933
+ });
934
+ printOutput(result ?? { success: true }, runtime.json);
935
+ });
936
+ roleCommand.command("assign <role> <member>").action(async (role, member, _options, command) => {
937
+ const { client, runtime } = await getClient(command);
938
+ const orgSlug = requireOrg(runtime);
939
+ const [roleId, userId] = await Promise.all([
940
+ resolveRoleId(client, orgSlug, role),
941
+ resolveMemberId(client, orgSlug, member)
942
+ ]);
943
+ const result = await runMutation(client, rolesApi.assign, {
944
+ orgSlug,
945
+ roleId,
946
+ userId
947
+ });
948
+ printOutput({ assignmentId: result }, runtime.json);
949
+ });
950
+ roleCommand.command("unassign <role> <member>").action(async (role, member, _options, command) => {
951
+ const { client, runtime } = await getClient(command);
952
+ const orgSlug = requireOrg(runtime);
953
+ const [roleId, userId] = await Promise.all([
954
+ resolveRoleId(client, orgSlug, role),
955
+ resolveMemberId(client, orgSlug, member)
956
+ ]);
957
+ const result = await runMutation(client, rolesApi.removeAssignment, {
958
+ orgSlug,
959
+ roleId,
960
+ userId
961
+ });
962
+ printOutput(result ?? { success: true }, runtime.json);
963
+ });
964
+ var inviteCommand = program.command("invite").description("Invitations");
965
+ inviteCommand.command("list").action(async (_options, command) => {
966
+ const { client, runtime } = await getClient(command);
967
+ const invites = await runQuery(client, api.users.getPendingInvitations, {});
968
+ printOutput(invites, runtime.json);
969
+ });
970
+ inviteCommand.command("accept <inviteId>").action(async (inviteId, _options, command) => {
971
+ const { client, runtime } = await getClient(command);
972
+ const result = await runMutation(
973
+ client,
974
+ api.organizations.mutations.acceptInvitation,
975
+ { inviteId }
976
+ );
977
+ printOutput(result ?? { success: true }, runtime.json);
978
+ });
979
+ inviteCommand.command("decline <inviteId>").action(async (inviteId, _options, command) => {
980
+ const { client, runtime } = await getClient(command);
981
+ const result = await runMutation(
982
+ client,
983
+ api.organizations.mutations.declineInvitation,
984
+ { inviteId }
985
+ );
986
+ printOutput(result ?? { success: true }, runtime.json);
987
+ });
988
+ program.command("refdata [slug]").action(async (slug, _options, command) => {
989
+ const { client, runtime } = await getClient(command);
990
+ const orgSlug = requireOrg(runtime, slug);
991
+ const result = await runAction(client, cliApi.listWorkspaceReferenceData, {
992
+ orgSlug
993
+ });
994
+ printOutput(result, runtime.json);
995
+ });
996
+ program.command("icons <query>").option("--limit <n>").action(async (query, options, command) => {
997
+ const { client, runtime } = await getClient(command);
998
+ const result = await runAction(client, cliApi.searchIcons, {
999
+ query,
1000
+ limit: options.limit ? Number(options.limit) : void 0
1001
+ });
1002
+ printOutput(result, runtime.json);
1003
+ });
1004
+ program.command("search <query>").option("--limit <n>").action(async (query, options, command) => {
1005
+ const { client, runtime } = await getClient(command);
1006
+ const orgSlug = requireOrg(runtime);
1007
+ const result = await runQuery(client, api.search.queries.searchEntities, {
1008
+ orgSlug,
1009
+ query,
1010
+ limit: optionalNumber(options.limit, "limit")
1011
+ });
1012
+ printOutput(result, runtime.json);
1013
+ });
1014
+ var permissionCommand = program.command("permission").description("Permission checks");
1015
+ permissionCommand.command("check <permission>").option("--team <teamKey>").option("--project <projectKey>").action(async (permission, options, command) => {
1016
+ const { client, runtime } = await getClient(command);
1017
+ const orgSlug = requireOrg(runtime);
1018
+ const [teamId, projectId] = await Promise.all([
1019
+ resolveTeamId(client, orgSlug, options.team),
1020
+ resolveProjectId(client, orgSlug, options.project)
1021
+ ]);
1022
+ const result = await runQuery(client, api.permissions.utils.has, {
1023
+ orgSlug,
1024
+ permission,
1025
+ teamId,
1026
+ projectId
1027
+ });
1028
+ printOutput(
1029
+ { permission, allowed: result, teamId, projectId },
1030
+ runtime.json
1031
+ );
1032
+ });
1033
+ permissionCommand.command("check-many <permissions>").option("--team <teamKey>").option("--project <projectKey>").action(async (permissions, options, command) => {
1034
+ const { client, runtime } = await getClient(command);
1035
+ const orgSlug = requireOrg(runtime);
1036
+ const [teamId, projectId] = await Promise.all([
1037
+ resolveTeamId(client, orgSlug, options.team),
1038
+ resolveProjectId(client, orgSlug, options.project)
1039
+ ]);
1040
+ const permissionList = parsePermissions(permissions);
1041
+ const result = await runQuery(client, api.permissions.utils.hasMultiple, {
1042
+ orgSlug,
1043
+ permissions: permissionList,
1044
+ teamId,
1045
+ projectId
1046
+ });
1047
+ printOutput(result, runtime.json);
1048
+ });
1049
+ var activityCommand = program.command("activity").description("Activity feed");
1050
+ activityCommand.command("project <projectKey>").option("--limit <n>").option("--cursor <cursor>").action(async (projectKey, options, command) => {
1051
+ const { client, runtime } = await getClient(command);
1052
+ const orgSlug = requireOrg(runtime);
1053
+ const projectId = await resolveProjectId(client, orgSlug, projectKey);
1054
+ const result = await runQuery(
1055
+ client,
1056
+ api.activities.queries.listProjectActivity,
1057
+ {
1058
+ projectId,
1059
+ paginationOpts: buildPaginationOptions(options.limit, options.cursor)
1060
+ }
1061
+ );
1062
+ printOutput(result, runtime.json);
1063
+ });
1064
+ activityCommand.command("team <teamKey>").option("--limit <n>").option("--cursor <cursor>").action(async (teamKey, options, command) => {
1065
+ const { client, runtime } = await getClient(command);
1066
+ const orgSlug = requireOrg(runtime);
1067
+ const teamId = await resolveTeamId(client, orgSlug, teamKey);
1068
+ const result = await runQuery(
1069
+ client,
1070
+ api.activities.queries.listTeamActivity,
1071
+ {
1072
+ teamId,
1073
+ paginationOpts: buildPaginationOptions(options.limit, options.cursor)
1074
+ }
1075
+ );
1076
+ printOutput(result, runtime.json);
1077
+ });
1078
+ activityCommand.command("issue <issueKey>").option("--limit <n>").option("--cursor <cursor>").action(async (issueKey, options, command) => {
1079
+ const { client, runtime } = await getClient(command);
1080
+ const orgSlug = requireOrg(runtime);
1081
+ const issueId = await resolveIssueId(client, orgSlug, issueKey);
1082
+ const result = await runQuery(
1083
+ client,
1084
+ api.activities.queries.listIssueActivity,
1085
+ {
1086
+ issueId,
1087
+ paginationOpts: buildPaginationOptions(options.limit, options.cursor)
1088
+ }
1089
+ );
1090
+ printOutput(result, runtime.json);
1091
+ });
1092
+ activityCommand.command("document <documentId>").option("--limit <n>").option("--cursor <cursor>").action(async (documentId, options, command) => {
1093
+ const { client, runtime } = await getClient(command);
1094
+ const orgSlug = requireOrg(runtime);
1095
+ const resolvedDocumentId = await resolveDocumentId(
1096
+ client,
1097
+ orgSlug,
1098
+ documentId
1099
+ );
1100
+ const result = await runQuery(
1101
+ client,
1102
+ api.activities.queries.listDocumentActivity,
1103
+ {
1104
+ documentId: resolvedDocumentId,
1105
+ paginationOpts: buildPaginationOptions(options.limit, options.cursor)
1106
+ }
1107
+ );
1108
+ printOutput(result, runtime.json);
1109
+ });
1110
+ var notificationCommand = program.command("notification").description("Notifications");
1111
+ notificationCommand.command("inbox").option("--filter <filter>", "all or unread").option("--limit <n>").option("--cursor <cursor>").action(async (options, command) => {
1112
+ const { client, runtime } = await getClient(command);
1113
+ const result = await runQuery(client, api.notifications.queries.listInbox, {
1114
+ filter: options.filter,
1115
+ paginationOpts: buildPaginationOptions(options.limit, options.cursor)
1116
+ });
1117
+ printOutput(result, runtime.json);
1118
+ });
1119
+ notificationCommand.command("unread-count").action(async (_options, command) => {
1120
+ const { client, runtime } = await getClient(command);
1121
+ const result = await runQuery(
1122
+ client,
1123
+ api.notifications.queries.unreadCount,
1124
+ {}
1125
+ );
1126
+ printOutput({ unreadCount: result }, runtime.json);
1127
+ });
1128
+ notificationCommand.command("mark-read <recipientId>").action(async (recipientId, _options, command) => {
1129
+ const { client, runtime } = await getClient(command);
1130
+ const result = await runMutation(
1131
+ client,
1132
+ api.notifications.mutations.markRead,
1133
+ {
1134
+ recipientId
1135
+ }
1136
+ );
1137
+ printOutput(result, runtime.json);
1138
+ });
1139
+ notificationCommand.command("mark-all-read").action(async (_options, command) => {
1140
+ const { client, runtime } = await getClient(command);
1141
+ const result = await runMutation(
1142
+ client,
1143
+ api.notifications.mutations.markAllRead,
1144
+ {}
1145
+ );
1146
+ printOutput(result, runtime.json);
1147
+ });
1148
+ notificationCommand.command("archive <recipientId>").action(async (recipientId, _options, command) => {
1149
+ const { client, runtime } = await getClient(command);
1150
+ const result = await runMutation(
1151
+ client,
1152
+ api.notifications.mutations.archive,
1153
+ {
1154
+ recipientId
1155
+ }
1156
+ );
1157
+ printOutput(result, runtime.json);
1158
+ });
1159
+ notificationCommand.command("preferences").action(async (_options, command) => {
1160
+ const { client, runtime } = await getClient(command);
1161
+ const result = await runQuery(
1162
+ client,
1163
+ api.notifications.queries.getPreferences,
1164
+ {}
1165
+ );
1166
+ printOutput(result, runtime.json);
1167
+ });
1168
+ notificationCommand.command("set-preference <category>").requiredOption("--in-app <true|false>").requiredOption("--email <true|false>").requiredOption("--push <true|false>").action(async (category, options, command) => {
1169
+ const { client, runtime } = await getClient(command);
1170
+ if (!NOTIFICATION_CATEGORIES.includes(category)) {
1171
+ throw new Error(
1172
+ `category must be one of: ${NOTIFICATION_CATEGORIES.join(", ")}`
1173
+ );
1174
+ }
1175
+ const result = await runMutation(
1176
+ client,
1177
+ api.notifications.mutations.updatePreferences,
1178
+ {
1179
+ category,
1180
+ inAppEnabled: parseBoolean(options.inApp, "in-app"),
1181
+ emailEnabled: parseBoolean(options.email, "email"),
1182
+ pushEnabled: parseBoolean(options.push, "push")
1183
+ }
1184
+ );
1185
+ printOutput(result, runtime.json);
1186
+ });
1187
+ notificationCommand.command("subscriptions").action(async (_options, command) => {
1188
+ const { client, runtime } = await getClient(command);
1189
+ const result = await runQuery(
1190
+ client,
1191
+ api.notifications.queries.listPushSubscriptions,
1192
+ {}
1193
+ );
1194
+ printOutput(result, runtime.json);
1195
+ });
1196
+ notificationCommand.command("remove-subscription <subscriptionId>").action(async (subscriptionId, _options, command) => {
1197
+ const { client, runtime } = await getClient(command);
1198
+ const result = await runMutation(
1199
+ client,
1200
+ api.notifications.mutations.removePushSubscription,
1201
+ { subscriptionId }
1202
+ );
1203
+ printOutput(result, runtime.json);
1204
+ });
1205
+ var priorityCommand = program.command("priority").description("Issue priorities");
1206
+ priorityCommand.command("list [slug]").action(async (slug, _options, command) => {
1207
+ const { client, runtime } = await getClient(command);
1208
+ const orgSlug = requireOrg(runtime, slug);
1209
+ const result = await runQuery(
1210
+ client,
1211
+ api.organizations.queries.listIssuePriorities,
1212
+ { orgSlug }
1213
+ );
1214
+ printOutput(result, runtime.json);
1215
+ });
1216
+ priorityCommand.command("create").requiredOption("--name <name>").requiredOption("--weight <n>").requiredOption("--color <hex>").option("--icon <icon>").action(async (options, command) => {
1217
+ const { client, runtime } = await getClient(command);
1218
+ const orgSlug = requireOrg(runtime);
1219
+ const result = await runMutation(
1220
+ client,
1221
+ api.organizations.mutations.createIssuePriority,
1222
+ {
1223
+ orgSlug,
1224
+ name: options.name,
1225
+ weight: requiredNumber(options.weight, "weight"),
1226
+ color: options.color,
1227
+ icon: options.icon
1228
+ }
1229
+ );
1230
+ printOutput(result, runtime.json);
1231
+ });
1232
+ priorityCommand.command("update <priority>").requiredOption("--name <name>").requiredOption("--color <hex>").option("--weight <n>").option("--icon <icon>").action(async (priority, options, command) => {
1233
+ const { client, runtime } = await getClient(command);
1234
+ const orgSlug = requireOrg(runtime);
1235
+ const priorityId = await resolveIssuePriorityId(client, orgSlug, priority);
1236
+ const result = await runMutation(
1237
+ client,
1238
+ api.organizations.mutations.updateIssuePriority,
1239
+ {
1240
+ orgSlug,
1241
+ priorityId,
1242
+ name: options.name,
1243
+ weight: optionalNumber(options.weight, "weight"),
1244
+ color: options.color,
1245
+ icon: options.icon
1246
+ }
1247
+ );
1248
+ printOutput(result ?? { success: true }, runtime.json);
1249
+ });
1250
+ priorityCommand.command("delete <priority>").action(async (priority, _options, command) => {
1251
+ const { client, runtime } = await getClient(command);
1252
+ const orgSlug = requireOrg(runtime);
1253
+ const priorityId = await resolveIssuePriorityId(client, orgSlug, priority);
1254
+ const result = await runMutation(
1255
+ client,
1256
+ api.organizations.mutations.deleteIssuePriority,
1257
+ {
1258
+ orgSlug,
1259
+ priorityId
1260
+ }
1261
+ );
1262
+ printOutput(result ?? { success: true }, runtime.json);
1263
+ });
1264
+ priorityCommand.command("reset [slug]").action(async (slug, _options, command) => {
1265
+ const { client, runtime } = await getClient(command);
1266
+ const orgSlug = requireOrg(runtime, slug);
1267
+ const result = await runMutation(
1268
+ client,
1269
+ api.organizations.mutations.resetIssuePriorities,
1270
+ { orgSlug }
1271
+ );
1272
+ printOutput(result ?? { success: true }, runtime.json);
1273
+ });
1274
+ var stateCommand = program.command("state").description("Issue states");
1275
+ stateCommand.command("list [slug]").action(async (slug, _options, command) => {
1276
+ const { client, runtime } = await getClient(command);
1277
+ const orgSlug = requireOrg(runtime, slug);
1278
+ const result = await runQuery(
1279
+ client,
1280
+ api.organizations.queries.listIssueStates,
1281
+ {
1282
+ orgSlug
1283
+ }
1284
+ );
1285
+ printOutput(result, runtime.json);
1286
+ });
1287
+ stateCommand.command("create").requiredOption("--name <name>").requiredOption("--position <n>").requiredOption("--type <type>").requiredOption("--color <hex>").option("--icon <icon>").action(async (options, command) => {
1288
+ const { client, runtime } = await getClient(command);
1289
+ const orgSlug = requireOrg(runtime);
1290
+ if (!ISSUE_STATE_TYPES.includes(options.type)) {
1291
+ throw new Error(`type must be one of: ${ISSUE_STATE_TYPES.join(", ")}`);
1292
+ }
1293
+ const result = await runMutation(
1294
+ client,
1295
+ api.organizations.mutations.createIssueState,
1296
+ {
1297
+ orgSlug,
1298
+ name: options.name,
1299
+ position: requiredNumber(options.position, "position"),
1300
+ type: options.type,
1301
+ color: options.color,
1302
+ icon: options.icon
1303
+ }
1304
+ );
1305
+ printOutput(result, runtime.json);
1306
+ });
1307
+ stateCommand.command("update <state>").requiredOption("--name <name>").requiredOption("--position <n>").requiredOption("--type <type>").requiredOption("--color <hex>").option("--icon <icon>").action(async (state, options, command) => {
1308
+ const { client, runtime } = await getClient(command);
1309
+ const orgSlug = requireOrg(runtime);
1310
+ if (!ISSUE_STATE_TYPES.includes(options.type)) {
1311
+ throw new Error(`type must be one of: ${ISSUE_STATE_TYPES.join(", ")}`);
1312
+ }
1313
+ const stateId = await resolveIssueStateId(client, orgSlug, state);
1314
+ const result = await runMutation(
1315
+ client,
1316
+ api.organizations.mutations.updateIssueState,
1317
+ {
1318
+ orgSlug,
1319
+ stateId,
1320
+ name: options.name,
1321
+ position: requiredNumber(options.position, "position"),
1322
+ type: options.type,
1323
+ color: options.color,
1324
+ icon: options.icon
1325
+ }
1326
+ );
1327
+ printOutput(result ?? { success: true }, runtime.json);
1328
+ });
1329
+ stateCommand.command("delete <state>").action(async (state, _options, command) => {
1330
+ const { client, runtime } = await getClient(command);
1331
+ const orgSlug = requireOrg(runtime);
1332
+ const stateId = await resolveIssueStateId(client, orgSlug, state);
1333
+ const result = await runMutation(
1334
+ client,
1335
+ api.organizations.mutations.deleteIssueState,
1336
+ {
1337
+ orgSlug,
1338
+ stateId
1339
+ }
1340
+ );
1341
+ printOutput(result ?? { success: true }, runtime.json);
1342
+ });
1343
+ stateCommand.command("reset [slug]").action(async (slug, _options, command) => {
1344
+ const { client, runtime } = await getClient(command);
1345
+ const orgSlug = requireOrg(runtime, slug);
1346
+ const result = await runMutation(
1347
+ client,
1348
+ api.organizations.mutations.resetIssueStates,
1349
+ { orgSlug }
1350
+ );
1351
+ printOutput(result ?? { success: true }, runtime.json);
1352
+ });
1353
+ var statusCommand = program.command("status").description("Project statuses");
1354
+ statusCommand.command("list [slug]").action(async (slug, _options, command) => {
1355
+ const { client, runtime } = await getClient(command);
1356
+ const orgSlug = requireOrg(runtime, slug);
1357
+ const result = await runQuery(
1358
+ client,
1359
+ api.organizations.queries.listProjectStatuses,
1360
+ { orgSlug }
1361
+ );
1362
+ printOutput(result, runtime.json);
1363
+ });
1364
+ statusCommand.command("create").requiredOption("--name <name>").requiredOption("--position <n>").requiredOption("--type <type>").requiredOption("--color <hex>").option("--icon <icon>").action(async (options, command) => {
1365
+ const { client, runtime } = await getClient(command);
1366
+ const orgSlug = requireOrg(runtime);
1367
+ if (!PROJECT_STATUS_TYPES.includes(options.type)) {
1368
+ throw new Error(
1369
+ `type must be one of: ${PROJECT_STATUS_TYPES.join(", ")}`
1370
+ );
1371
+ }
1372
+ const result = await runMutation(
1373
+ client,
1374
+ api.organizations.mutations.createProjectStatus,
1375
+ {
1376
+ orgSlug,
1377
+ name: options.name,
1378
+ position: requiredNumber(options.position, "position"),
1379
+ type: options.type,
1380
+ color: options.color,
1381
+ icon: options.icon
1382
+ }
1383
+ );
1384
+ printOutput(result, runtime.json);
1385
+ });
1386
+ statusCommand.command("update <status>").requiredOption("--name <name>").requiredOption("--position <n>").requiredOption("--type <type>").requiredOption("--color <hex>").option("--icon <icon>").action(async (status, options, command) => {
1387
+ const { client, runtime } = await getClient(command);
1388
+ const orgSlug = requireOrg(runtime);
1389
+ if (!PROJECT_STATUS_TYPES.includes(options.type)) {
1390
+ throw new Error(
1391
+ `type must be one of: ${PROJECT_STATUS_TYPES.join(", ")}`
1392
+ );
1393
+ }
1394
+ const statusId = await resolveProjectStatusId(client, orgSlug, status);
1395
+ const result = await runMutation(
1396
+ client,
1397
+ api.organizations.mutations.updateProjectStatus,
1398
+ {
1399
+ orgSlug,
1400
+ statusId,
1401
+ name: options.name,
1402
+ position: requiredNumber(options.position, "position"),
1403
+ type: options.type,
1404
+ color: options.color,
1405
+ icon: options.icon
1406
+ }
1407
+ );
1408
+ printOutput(result ?? { success: true }, runtime.json);
1409
+ });
1410
+ statusCommand.command("delete <status>").action(async (status, _options, command) => {
1411
+ const { client, runtime } = await getClient(command);
1412
+ const orgSlug = requireOrg(runtime);
1413
+ const statusId = await resolveProjectStatusId(client, orgSlug, status);
1414
+ const result = await runMutation(
1415
+ client,
1416
+ api.organizations.mutations.deleteProjectStatus,
1417
+ {
1418
+ orgSlug,
1419
+ statusId
1420
+ }
1421
+ );
1422
+ printOutput(result ?? { success: true }, runtime.json);
1423
+ });
1424
+ statusCommand.command("reset [slug]").action(async (slug, _options, command) => {
1425
+ const { client, runtime } = await getClient(command);
1426
+ const orgSlug = requireOrg(runtime, slug);
1427
+ const result = await runMutation(
1428
+ client,
1429
+ api.organizations.mutations.resetProjectStatuses,
1430
+ { orgSlug }
1431
+ );
1432
+ printOutput(result ?? { success: true }, runtime.json);
1433
+ });
1434
+ var adminCommand = program.command("admin").description("Platform admin");
1435
+ adminCommand.command("branding").action(async (_options, command) => {
1436
+ const { client, runtime } = await getClient(command);
1437
+ const result = await runQuery(
1438
+ client,
1439
+ api.platformAdmin.queries.getBranding,
1440
+ {}
1441
+ );
1442
+ printOutput(result, runtime.json);
1443
+ });
1444
+ adminCommand.command("set-branding").option("--name <name>").option("--description <description>").option("--theme-color <hex>").option("--accent-color <hex>").option("--logo <path>").option("--remove-logo").action(async (options, command) => {
1445
+ const { client, runtime } = await getClient(command);
1446
+ let logoStorageId;
1447
+ if (options.logo) {
1448
+ const uploadUrl = await runMutation(
1449
+ client,
1450
+ api.platformAdmin.mutations.generateBrandLogoUploadUrl,
1451
+ {}
1452
+ );
1453
+ logoStorageId = await uploadFile(uploadUrl, options.logo);
1454
+ }
1455
+ const result = await runMutation(
1456
+ client,
1457
+ api.platformAdmin.mutations.updateBranding,
1458
+ {
1459
+ name: options.name,
1460
+ description: options.description,
1461
+ logoStorageId,
1462
+ removeLogo: options.removeLogo ? true : void 0,
1463
+ themeColor: options.themeColor,
1464
+ accentColor: options.accentColor
1465
+ }
1466
+ );
1467
+ printOutput(
1468
+ {
1469
+ ...result ?? { success: true },
1470
+ logoStorageId: logoStorageId ?? null
1471
+ },
1472
+ runtime.json
1473
+ );
1474
+ });
1475
+ adminCommand.command("signup-policy").action(async (_options, command) => {
1476
+ const { client, runtime } = await getClient(command);
1477
+ const result = await runQuery(
1478
+ client,
1479
+ api.platformAdmin.queries.getSignupPolicy,
1480
+ {}
1481
+ );
1482
+ printOutput(result, runtime.json);
1483
+ });
1484
+ adminCommand.command("set-signup-policy").option("--blocked <domains>").option("--allowed <domains>").action(async (options, command) => {
1485
+ const { client, runtime } = await getClient(command);
1486
+ const result = await runMutation(
1487
+ client,
1488
+ api.platformAdmin.mutations.updateSignupEmailDomainPolicy,
1489
+ {
1490
+ blockedDomains: parseList(options.blocked),
1491
+ allowedDomains: parseList(options.allowed)
1492
+ }
1493
+ );
1494
+ printOutput(result ?? { success: true }, runtime.json);
1495
+ });
1496
+ adminCommand.command("sync-disposable-domains").action(async (_options, command) => {
1497
+ const { client, runtime } = await getClient(command);
1498
+ const result = await runAction(
1499
+ client,
1500
+ api.platformAdmin.actions.runDisposableDomainSyncNow,
1501
+ {}
1502
+ );
1503
+ printOutput(result, runtime.json);
1504
+ });
1505
+ var teamCommand = program.command("team").description("Teams");
1506
+ teamCommand.command("list [slug]").option("--limit <n>").action(async (slug, options, command) => {
1507
+ const { client, runtime } = await getClient(command);
1508
+ const orgSlug = requireOrg(runtime, slug);
1509
+ const result = await runAction(client, cliApi.listTeams, {
1510
+ orgSlug,
1511
+ limit: options.limit ? Number(options.limit) : void 0
1512
+ });
1513
+ printOutput(result, runtime.json);
1514
+ });
1515
+ teamCommand.command("get <teamKey>").action(async (teamKey, _options, command) => {
1516
+ const { client, runtime } = await getClient(command);
1517
+ const orgSlug = requireOrg(runtime);
1518
+ const result = await runAction(client, cliApi.getTeam, {
1519
+ orgSlug,
1520
+ teamKey
1521
+ });
1522
+ printOutput(result, runtime.json);
1523
+ });
1524
+ teamCommand.command("create").requiredOption("--key <key>").requiredOption("--name <name>").option("--description <description>").option("--visibility <visibility>").option("--icon <icon>").option("--color <color>").action(async (options, command) => {
1525
+ const { client, runtime } = await getClient(command);
1526
+ const orgSlug = requireOrg(runtime);
1527
+ const result = await runAction(client, cliApi.createTeam, {
1528
+ orgSlug,
1529
+ key: options.key,
1530
+ name: options.name,
1531
+ description: options.description,
1532
+ visibility: options.visibility,
1533
+ icon: options.icon,
1534
+ color: options.color
1535
+ });
1536
+ printOutput(result, runtime.json);
1537
+ });
1538
+ teamCommand.command("update <teamKey>").option("--name <name>").option("--description <description>").option("--clear-description").option("--visibility <visibility>").option("--icon <icon>").option("--clear-icon").option("--color <color>").option("--clear-color").action(async (teamKey, options, command) => {
1539
+ const { client, runtime } = await getClient(command);
1540
+ const orgSlug = requireOrg(runtime);
1541
+ const result = await runAction(client, cliApi.updateTeam, {
1542
+ orgSlug,
1543
+ teamKey,
1544
+ name: options.name,
1545
+ description: nullableOption(
1546
+ options.description,
1547
+ options.clearDescription
1548
+ ),
1549
+ visibility: options.visibility,
1550
+ icon: nullableOption(options.icon, options.clearIcon),
1551
+ color: nullableOption(options.color, options.clearColor)
1552
+ });
1553
+ printOutput(result, runtime.json);
1554
+ });
1555
+ teamCommand.command("delete <teamKey>").action(async (teamKey, _options, command) => {
1556
+ const { client, runtime } = await getClient(command);
1557
+ const orgSlug = requireOrg(runtime);
1558
+ const result = await runAction(client, cliApi.deleteTeam, {
1559
+ orgSlug,
1560
+ teamKey
1561
+ });
1562
+ printOutput(result, runtime.json);
1563
+ });
1564
+ teamCommand.command("members <teamKey>").action(async (teamKey, _options, command) => {
1565
+ const { client, runtime } = await getClient(command);
1566
+ const orgSlug = requireOrg(runtime);
1567
+ const team = await runAction(client, cliApi.getTeam, { orgSlug, teamKey });
1568
+ const result = await runQuery(client, api.teams.queries.listMembers, {
1569
+ teamId: team.id
1570
+ });
1571
+ printOutput(result, runtime.json);
1572
+ });
1573
+ teamCommand.command("add-member <teamKey> <member>").option("--role <role>", "member or lead", "member").action(async (teamKey, member, options, command) => {
1574
+ const { client, runtime } = await getClient(command);
1575
+ const orgSlug = requireOrg(runtime);
1576
+ const result = await runAction(client, cliApi.addTeamMember, {
1577
+ orgSlug,
1578
+ teamKey,
1579
+ memberName: member,
1580
+ role: options.role
1581
+ });
1582
+ printOutput(result, runtime.json);
1583
+ });
1584
+ teamCommand.command("remove-member <teamKey> <member>").action(async (teamKey, member, _options, command) => {
1585
+ const { client, runtime } = await getClient(command);
1586
+ const orgSlug = requireOrg(runtime);
1587
+ const result = await runAction(client, cliApi.removeTeamMember, {
1588
+ orgSlug,
1589
+ teamKey,
1590
+ memberName: member
1591
+ });
1592
+ printOutput(result, runtime.json);
1593
+ });
1594
+ teamCommand.command("set-lead <teamKey> <member>").action(async (teamKey, member, _options, command) => {
1595
+ const { client, runtime } = await getClient(command);
1596
+ const orgSlug = requireOrg(runtime);
1597
+ const leadName = member === "null" ? null : member;
1598
+ const result = await runAction(client, cliApi.changeTeamLead, {
1599
+ orgSlug,
1600
+ teamKey,
1601
+ leadName
1602
+ });
1603
+ printOutput(result, runtime.json);
1604
+ });
1605
+ var projectCommand = program.command("project").description("Projects");
1606
+ projectCommand.command("list [slug]").option("--team <teamKey>").option("--limit <n>").action(async (slug, options, command) => {
1607
+ const { client, runtime } = await getClient(command);
1608
+ const orgSlug = requireOrg(runtime, slug);
1609
+ const result = await runAction(client, cliApi.listProjects, {
1610
+ orgSlug,
1611
+ teamKey: options.team,
1612
+ limit: options.limit ? Number(options.limit) : void 0
1613
+ });
1614
+ printOutput(result, runtime.json);
1615
+ });
1616
+ projectCommand.command("get <projectKey>").action(async (projectKey, _options, command) => {
1617
+ const { client, runtime } = await getClient(command);
1618
+ const orgSlug = requireOrg(runtime);
1619
+ const result = await runAction(client, cliApi.getProject, {
1620
+ orgSlug,
1621
+ projectKey
1622
+ });
1623
+ printOutput(result, runtime.json);
1624
+ });
1625
+ projectCommand.command("create").requiredOption("--key <key>").requiredOption("--name <name>").option("--description <description>").option("--team <teamKey>").option("--status <statusName>").option("--visibility <visibility>").option("--icon <icon>").option("--color <color>").action(async (options, command) => {
1626
+ const { client, runtime } = await getClient(command);
1627
+ const orgSlug = requireOrg(runtime);
1628
+ const result = await runAction(client, cliApi.createProject, {
1629
+ orgSlug,
1630
+ key: options.key,
1631
+ name: options.name,
1632
+ description: options.description,
1633
+ teamKey: options.team,
1634
+ statusName: options.status,
1635
+ visibility: options.visibility,
1636
+ icon: options.icon,
1637
+ color: options.color
1638
+ });
1639
+ printOutput(result, runtime.json);
1640
+ });
1641
+ projectCommand.command("update <projectKey>").option("--name <name>").option("--description <description>").option("--team <teamKey>").option("--clear-team").option("--status <statusName>").option("--clear-status").option("--visibility <visibility>").option("--start-date <date>").option("--clear-start-date").option("--due-date <date>").option("--clear-due-date").option("--icon <icon>").option("--clear-icon").option("--color <color>").option("--clear-color").action(async (projectKey, options, command) => {
1642
+ const { client, runtime } = await getClient(command);
1643
+ const orgSlug = requireOrg(runtime);
1644
+ const result = await runAction(client, cliApi.updateProject, {
1645
+ orgSlug,
1646
+ projectKey,
1647
+ name: options.name,
1648
+ description: options.description,
1649
+ teamKey: nullableOption(options.team, options.clearTeam),
1650
+ statusName: nullableOption(options.status, options.clearStatus),
1651
+ visibility: options.visibility,
1652
+ startDate: nullableOption(options.startDate, options.clearStartDate),
1653
+ dueDate: nullableOption(options.dueDate, options.clearDueDate),
1654
+ icon: nullableOption(options.icon, options.clearIcon),
1655
+ color: nullableOption(options.color, options.clearColor)
1656
+ });
1657
+ printOutput(result, runtime.json);
1658
+ });
1659
+ projectCommand.command("delete <projectKey>").action(async (projectKey, _options, command) => {
1660
+ const { client, runtime } = await getClient(command);
1661
+ const orgSlug = requireOrg(runtime);
1662
+ const result = await runAction(client, cliApi.deleteProject, {
1663
+ orgSlug,
1664
+ projectKey
1665
+ });
1666
+ printOutput(result, runtime.json);
1667
+ });
1668
+ projectCommand.command("members <projectKey>").action(async (projectKey, _options, command) => {
1669
+ const { client, runtime } = await getClient(command);
1670
+ const orgSlug = requireOrg(runtime);
1671
+ const project = await runAction(client, cliApi.getProject, {
1672
+ orgSlug,
1673
+ projectKey
1674
+ });
1675
+ const result = await runQuery(client, api.projects.queries.listMembers, {
1676
+ projectId: project.id
1677
+ });
1678
+ printOutput(result, runtime.json);
1679
+ });
1680
+ projectCommand.command("add-member <projectKey> <member>").option("--role <role>", "member or lead", "member").action(async (projectKey, member, options, command) => {
1681
+ const { client, runtime } = await getClient(command);
1682
+ const orgSlug = requireOrg(runtime);
1683
+ const result = await runAction(client, cliApi.addProjectMember, {
1684
+ orgSlug,
1685
+ projectKey,
1686
+ memberName: member,
1687
+ role: options.role
1688
+ });
1689
+ printOutput(result, runtime.json);
1690
+ });
1691
+ projectCommand.command("remove-member <projectKey> <member>").action(async (projectKey, member, _options, command) => {
1692
+ const { client, runtime } = await getClient(command);
1693
+ const orgSlug = requireOrg(runtime);
1694
+ const result = await runAction(client, cliApi.removeProjectMember, {
1695
+ orgSlug,
1696
+ projectKey,
1697
+ memberName: member
1698
+ });
1699
+ printOutput(result, runtime.json);
1700
+ });
1701
+ projectCommand.command("set-lead <projectKey> <member>").action(async (projectKey, member, _options, command) => {
1702
+ const { client, runtime } = await getClient(command);
1703
+ const orgSlug = requireOrg(runtime);
1704
+ const leadName = member === "null" ? null : member;
1705
+ const result = await runAction(client, cliApi.changeProjectLead, {
1706
+ orgSlug,
1707
+ projectKey,
1708
+ leadName
1709
+ });
1710
+ printOutput(result, runtime.json);
1711
+ });
1712
+ var issueCommand = program.command("issue").description("Issues");
1713
+ issueCommand.command("list [slug]").option("--project <projectKey>").option("--team <teamKey>").option("--limit <n>").action(async (slug, options, command) => {
1714
+ const { client, runtime } = await getClient(command);
1715
+ const orgSlug = requireOrg(runtime, slug);
1716
+ const result = await runAction(client, cliApi.listIssues, {
1717
+ orgSlug,
1718
+ projectKey: options.project,
1719
+ teamKey: options.team,
1720
+ limit: options.limit ? Number(options.limit) : void 0
1721
+ });
1722
+ printOutput(result, runtime.json);
1723
+ });
1724
+ issueCommand.command("get <issueKey>").action(async (issueKey, _options, command) => {
1725
+ const { client, runtime } = await getClient(command);
1726
+ const orgSlug = requireOrg(runtime);
1727
+ const result = await runAction(client, cliApi.getIssue, {
1728
+ orgSlug,
1729
+ issueKey
1730
+ });
1731
+ printOutput(result, runtime.json);
1732
+ });
1733
+ issueCommand.command("create").requiredOption("--title <title>").option("--description <description>").option("--project <projectKey>").option("--team <teamKey>").option("--priority <priorityName>").option("--visibility <visibility>").option("--assignee <member>").option("--state <stateName>").option("--start-date <date>").option("--due-date <date>").option("--parent <issueKey>").action(async (options, command) => {
1734
+ const { client, runtime } = await getClient(command);
1735
+ const orgSlug = requireOrg(runtime);
1736
+ const result = await runAction(client, cliApi.createIssue, {
1737
+ orgSlug,
1738
+ title: options.title,
1739
+ description: options.description,
1740
+ projectKey: options.project,
1741
+ teamKey: options.team,
1742
+ priorityName: options.priority,
1743
+ visibility: options.visibility,
1744
+ assigneeName: options.assignee,
1745
+ stateName: options.state,
1746
+ startDate: options.startDate,
1747
+ dueDate: options.dueDate,
1748
+ parentIssueKey: options.parent
1749
+ });
1750
+ printOutput(result, runtime.json);
1751
+ });
1752
+ issueCommand.command("update <issueKey>").option("--title <title>").option("--description <description>").option("--priority <priorityName>").option("--clear-priority").option("--team <teamKey>").option("--clear-team").option("--project <projectKey>").option("--clear-project").option("--visibility <visibility>").option("--assignee <member>").option("--clear-assignee").option("--state <stateName>").option("--start-date <date>").option("--clear-start-date").option("--due-date <date>").option("--clear-due-date").option("--parent <issueKey>").option("--clear-parent").action(async (issueKey, options, command) => {
1753
+ const { client, runtime } = await getClient(command);
1754
+ const orgSlug = requireOrg(runtime);
1755
+ const result = await runAction(client, cliApi.updateIssue, {
1756
+ orgSlug,
1757
+ issueKey,
1758
+ title: options.title,
1759
+ description: options.description,
1760
+ priorityName: nullableOption(options.priority, options.clearPriority),
1761
+ teamKey: nullableOption(options.team, options.clearTeam),
1762
+ projectKey: nullableOption(options.project, options.clearProject),
1763
+ visibility: options.visibility,
1764
+ assigneeName: nullableOption(options.assignee, options.clearAssignee),
1765
+ stateName: options.state,
1766
+ startDate: nullableOption(options.startDate, options.clearStartDate),
1767
+ dueDate: nullableOption(options.dueDate, options.clearDueDate),
1768
+ parentIssueKey: nullableOption(options.parent, options.clearParent)
1769
+ });
1770
+ printOutput(result, runtime.json);
1771
+ });
1772
+ issueCommand.command("delete <issueKey>").action(async (issueKey, _options, command) => {
1773
+ const { client, runtime } = await getClient(command);
1774
+ const orgSlug = requireOrg(runtime);
1775
+ const result = await runAction(client, cliApi.deleteIssue, {
1776
+ orgSlug,
1777
+ issueKey
1778
+ });
1779
+ printOutput(result, runtime.json);
1780
+ });
1781
+ issueCommand.command("assign <issueKey> <member>").option("--state <stateName>").action(async (issueKey, member, options, command) => {
1782
+ const { client, runtime } = await getClient(command);
1783
+ const orgSlug = requireOrg(runtime);
1784
+ const result = await runAction(client, cliApi.assignIssue, {
1785
+ orgSlug,
1786
+ issueKey,
1787
+ assigneeName: member,
1788
+ stateName: options.state
1789
+ });
1790
+ printOutput(result, runtime.json);
1791
+ });
1792
+ issueCommand.command("unassign <issueKey> <member>").action(async (issueKey, member, _options, command) => {
1793
+ const { client, runtime } = await getClient(command);
1794
+ const orgSlug = requireOrg(runtime);
1795
+ const result = await runAction(client, cliApi.unassignIssue, {
1796
+ orgSlug,
1797
+ issueKey,
1798
+ assigneeName: member
1799
+ });
1800
+ printOutput(result, runtime.json);
1801
+ });
1802
+ issueCommand.command("assignments <issueKey>").action(async (issueKey, _options, command) => {
1803
+ const { client, runtime } = await getClient(command);
1804
+ const orgSlug = requireOrg(runtime);
1805
+ const issueId = await resolveIssueId(client, orgSlug, issueKey);
1806
+ const result = await runQuery(client, api.issues.queries.getAssignments, {
1807
+ issueId
1808
+ });
1809
+ printOutput(result, runtime.json);
1810
+ });
1811
+ issueCommand.command("set-assignment-state <assignmentId> <state>").action(async (assignmentId, state, _options, command) => {
1812
+ const { client, runtime } = await getClient(command);
1813
+ const orgSlug = requireOrg(runtime);
1814
+ const stateId = await resolveIssueStateId(client, orgSlug, state);
1815
+ const result = await runMutation(
1816
+ client,
1817
+ api.issues.mutations.changeAssignmentState,
1818
+ {
1819
+ assignmentId,
1820
+ stateId
1821
+ }
1822
+ );
1823
+ printOutput(result ?? { success: true }, runtime.json);
1824
+ });
1825
+ issueCommand.command("reassign-assignment <assignmentId> <member>").action(async (assignmentId, member, _options, command) => {
1826
+ const { client, runtime } = await getClient(command);
1827
+ const orgSlug = requireOrg(runtime);
1828
+ const assigneeId = await resolveMemberId(client, orgSlug, member);
1829
+ const result = await runMutation(
1830
+ client,
1831
+ api.issues.mutations.updateAssignmentAssignee,
1832
+ {
1833
+ assignmentId,
1834
+ assigneeId
1835
+ }
1836
+ );
1837
+ printOutput(result ?? { success: true }, runtime.json);
1838
+ });
1839
+ issueCommand.command("remove-assignment <assignmentId>").action(async (assignmentId, _options, command) => {
1840
+ const { client, runtime } = await getClient(command);
1841
+ const result = await runMutation(
1842
+ client,
1843
+ api.issues.mutations.deleteAssignment,
1844
+ {
1845
+ assignmentId
1846
+ }
1847
+ );
1848
+ printOutput(result ?? { success: true }, runtime.json);
1849
+ });
1850
+ issueCommand.command("set-priority <issueKey> <priority>").action(async (issueKey, priority, _options, command) => {
1851
+ const { client, runtime } = await getClient(command);
1852
+ const orgSlug = requireOrg(runtime);
1853
+ const [issueId, priorityId] = await Promise.all([
1854
+ resolveIssueId(client, orgSlug, issueKey),
1855
+ resolveIssuePriorityId(client, orgSlug, priority)
1856
+ ]);
1857
+ const result = await runMutation(
1858
+ client,
1859
+ api.issues.mutations.changePriority,
1860
+ {
1861
+ issueId,
1862
+ priorityId
1863
+ }
1864
+ );
1865
+ printOutput(result ?? { success: true }, runtime.json);
1866
+ });
1867
+ issueCommand.command("replace-assignees <issueKey> <members>").action(async (issueKey, members, _options, command) => {
1868
+ const { client, runtime } = await getClient(command);
1869
+ const orgSlug = requireOrg(runtime);
1870
+ const issueId = await resolveIssueId(client, orgSlug, issueKey);
1871
+ const assigneeIds = await Promise.all(
1872
+ parseList(members).map(
1873
+ (member) => resolveMemberId(client, orgSlug, member)
1874
+ )
1875
+ );
1876
+ const result = await runMutation(
1877
+ client,
1878
+ api.issues.mutations.updateAssignees,
1879
+ {
1880
+ issueId,
1881
+ assigneeIds
1882
+ }
1883
+ );
1884
+ printOutput(result ?? { success: true }, runtime.json);
1885
+ });
1886
+ issueCommand.command("set-estimates <issueKey>").requiredOption("--values <state=hours,...>").action(async (issueKey, options, command) => {
1887
+ const { client, runtime } = await getClient(command);
1888
+ const orgSlug = requireOrg(runtime);
1889
+ const issueId = await resolveIssueId(client, orgSlug, issueKey);
1890
+ const estimatedTimes = await parseEstimatedTimes(
1891
+ client,
1892
+ orgSlug,
1893
+ options.values
1894
+ );
1895
+ const result = await runMutation(
1896
+ client,
1897
+ api.issues.mutations.updateEstimatedTimes,
1898
+ {
1899
+ issueId,
1900
+ estimatedTimes
1901
+ }
1902
+ );
1903
+ printOutput(result ?? { success: true }, runtime.json);
1904
+ });
1905
+ issueCommand.command("comment <issueKey>").requiredOption("--body <body>").action(async (issueKey, options, command) => {
1906
+ const { client, runtime } = await getClient(command);
1907
+ const orgSlug = requireOrg(runtime);
1908
+ const issue = await runAction(client, cliApi.getIssue, {
1909
+ orgSlug,
1910
+ issueKey
1911
+ });
1912
+ const result = await runMutation(client, api.issues.mutations.addComment, {
1913
+ issueId: issue.id,
1914
+ body: options.body
1915
+ });
1916
+ printOutput(result, runtime.json);
1917
+ });
1918
+ var documentCommand = program.command("document").description("Documents");
1919
+ documentCommand.command("list [slug]").option("--folder-id <id>").option("--limit <n>").action(async (slug, options, command) => {
1920
+ const { client, runtime } = await getClient(command);
1921
+ const orgSlug = requireOrg(runtime, slug);
1922
+ const result = await runAction(client, cliApi.listDocuments, {
1923
+ orgSlug,
1924
+ folderId: options.folderId,
1925
+ limit: options.limit ? Number(options.limit) : void 0
1926
+ });
1927
+ printOutput(result, runtime.json);
1928
+ });
1929
+ documentCommand.command("get <documentId>").action(async (documentId, _options, command) => {
1930
+ const { client, runtime } = await getClient(command);
1931
+ const orgSlug = requireOrg(runtime);
1932
+ const result = await runAction(client, cliApi.getDocument, {
1933
+ orgSlug,
1934
+ documentId
1935
+ });
1936
+ printOutput(result, runtime.json);
1937
+ });
1938
+ documentCommand.command("create").requiredOption("--title <title>").option("--content <content>").option("--team <teamKey>").option("--project <projectKey>").option("--folder-id <id>").option("--visibility <visibility>").option("--icon <icon>").option("--color <color>").action(async (options, command) => {
1939
+ const { client, runtime } = await getClient(command);
1940
+ const orgSlug = requireOrg(runtime);
1941
+ const result = await runAction(client, cliApi.createDocument, {
1942
+ orgSlug,
1943
+ title: options.title,
1944
+ content: options.content,
1945
+ teamKey: options.team,
1946
+ projectKey: options.project,
1947
+ folderId: options.folderId,
1948
+ visibility: options.visibility,
1949
+ icon: options.icon,
1950
+ color: options.color
1951
+ });
1952
+ printOutput(result, runtime.json);
1953
+ });
1954
+ documentCommand.command("update <documentId>").option("--title <title>").option("--content <content>").option("--team <teamKey>").option("--clear-team").option("--project <projectKey>").option("--clear-project").option("--folder-id <id>").option("--clear-folder").option("--visibility <visibility>").option("--icon <icon>").option("--clear-icon").option("--color <color>").option("--clear-color").action(async (documentId, options, command) => {
1955
+ const { client, runtime } = await getClient(command);
1956
+ const orgSlug = requireOrg(runtime);
1957
+ const result = await runAction(client, cliApi.updateDocument, {
1958
+ orgSlug,
1959
+ documentId,
1960
+ title: options.title,
1961
+ content: options.content,
1962
+ teamKey: nullableOption(options.team, options.clearTeam),
1963
+ projectKey: nullableOption(options.project, options.clearProject),
1964
+ folderId: nullableOption(options.folderId, options.clearFolder),
1965
+ visibility: options.visibility,
1966
+ icon: nullableOption(options.icon, options.clearIcon),
1967
+ color: nullableOption(options.color, options.clearColor)
1968
+ });
1969
+ printOutput(result, runtime.json);
1970
+ });
1971
+ documentCommand.command("move <documentId>").option("--folder-id <id>").option("--clear-folder").action(async (documentId, options, command) => {
1972
+ const { client, runtime } = await getClient(command);
1973
+ const orgSlug = requireOrg(runtime);
1974
+ const folderId = options.clearFolder ? null : requiredString(options.folderId, "folder-id");
1975
+ const result = await runAction(client, cliApi.moveDocumentToFolder, {
1976
+ orgSlug,
1977
+ documentId,
1978
+ folderId
1979
+ });
1980
+ printOutput(result, runtime.json);
1981
+ });
1982
+ documentCommand.command("delete <documentId>").action(async (documentId, _options, command) => {
1983
+ const { client, runtime } = await getClient(command);
1984
+ const orgSlug = requireOrg(runtime);
1985
+ const result = await runAction(client, cliApi.deleteDocument, {
1986
+ orgSlug,
1987
+ documentId
1988
+ });
1989
+ printOutput(result, runtime.json);
1990
+ });
1991
+ var folderCommand = program.command("folder").description("Document folders");
1992
+ folderCommand.command("list [slug]").action(async (slug, _options, command) => {
1993
+ const { client, runtime } = await getClient(command);
1994
+ const orgSlug = requireOrg(runtime, slug);
1995
+ const result = await runAction(client, cliApi.listFolders, { orgSlug });
1996
+ printOutput(result, runtime.json);
1997
+ });
1998
+ folderCommand.command("create").requiredOption("--name <name>").option("--description <description>").option("--icon <icon>").option("--color <color>").action(async (options, command) => {
1999
+ const { client, runtime } = await getClient(command);
2000
+ const orgSlug = requireOrg(runtime);
2001
+ const result = await runAction(client, cliApi.createFolder, {
2002
+ orgSlug,
2003
+ name: options.name,
2004
+ description: options.description,
2005
+ icon: options.icon,
2006
+ color: options.color
2007
+ });
2008
+ printOutput(result, runtime.json);
2009
+ });
2010
+ folderCommand.command("update <folderId>").option("--name <name>").option("--description <description>").option("--clear-description").option("--icon <icon>").option("--clear-icon").option("--color <color>").option("--clear-color").action(async (folderId, options, command) => {
2011
+ const { client, runtime } = await getClient(command);
2012
+ const orgSlug = requireOrg(runtime);
2013
+ const result = await runAction(client, cliApi.updateFolder, {
2014
+ orgSlug,
2015
+ folderId,
2016
+ name: options.name,
2017
+ description: nullableOption(
2018
+ options.description,
2019
+ options.clearDescription
2020
+ ),
2021
+ icon: nullableOption(options.icon, options.clearIcon),
2022
+ color: nullableOption(options.color, options.clearColor)
2023
+ });
2024
+ printOutput(result, runtime.json);
2025
+ });
2026
+ folderCommand.command("delete <folderId>").action(async (folderId, _options, command) => {
2027
+ const { client, runtime } = await getClient(command);
2028
+ const orgSlug = requireOrg(runtime);
2029
+ const result = await runAction(client, cliApi.deleteFolder, {
2030
+ orgSlug,
2031
+ folderId
2032
+ });
2033
+ printOutput(result, runtime.json);
2034
+ });
2035
+ async function main() {
2036
+ await program.parseAsync(process.argv);
2037
+ }
2038
+ main().catch((error) => {
2039
+ console.error(error instanceof Error ? error.message : String(error));
2040
+ process.exitCode = 1;
2041
+ });
2042
+ //# sourceMappingURL=index.js.map