@nathapp/koda-cli 0.2.4 → 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.
Files changed (103) hide show
  1. package/dist/commands/agent.d.ts.map +1 -1
  2. package/dist/commands/agent.js +14 -20
  3. package/dist/commands/agent.js.map +1 -1
  4. package/dist/commands/comment.d.ts.map +1 -1
  5. package/dist/commands/comment.js +118 -6
  6. package/dist/commands/comment.js.map +1 -1
  7. package/dist/commands/init.d.ts +1 -0
  8. package/dist/commands/init.d.ts.map +1 -1
  9. package/dist/commands/init.js +9 -7
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/commands/kb.d.ts.map +1 -1
  12. package/dist/commands/kb.js +105 -9
  13. package/dist/commands/kb.js.map +1 -1
  14. package/dist/commands/label.d.ts.map +1 -1
  15. package/dist/commands/label.js +72 -29
  16. package/dist/commands/label.js.map +1 -1
  17. package/dist/commands/login.d.ts.map +1 -1
  18. package/dist/commands/login.js +7 -5
  19. package/dist/commands/login.js.map +1 -1
  20. package/dist/commands/project.d.ts.map +1 -1
  21. package/dist/commands/project.js +86 -26
  22. package/dist/commands/project.js.map +1 -1
  23. package/dist/commands/ticket.d.ts.map +1 -1
  24. package/dist/commands/ticket.js +199 -201
  25. package/dist/commands/ticket.js.map +1 -1
  26. package/dist/commands/vcs-messages.d.ts +22 -0
  27. package/dist/commands/vcs-messages.d.ts.map +1 -0
  28. package/dist/commands/vcs-messages.js +25 -0
  29. package/dist/commands/vcs-messages.js.map +1 -0
  30. package/dist/commands/vcs.d.ts +10 -0
  31. package/dist/commands/vcs.d.ts.map +1 -0
  32. package/dist/commands/vcs.js +376 -0
  33. package/dist/commands/vcs.js.map +1 -0
  34. package/dist/config.d.ts +1 -0
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/config.js +2 -2
  37. package/dist/config.js.map +1 -1
  38. package/dist/generated/core/ApiError.d.ts +11 -0
  39. package/dist/generated/core/ApiError.d.ts.map +1 -0
  40. package/dist/generated/core/ApiError.js +21 -0
  41. package/dist/generated/core/ApiError.js.map +1 -0
  42. package/dist/generated/core/ApiRequestOptions.d.ts +14 -0
  43. package/dist/generated/core/ApiRequestOptions.d.ts.map +1 -0
  44. package/dist/generated/core/ApiRequestOptions.js +3 -0
  45. package/dist/generated/core/ApiRequestOptions.js.map +1 -0
  46. package/dist/generated/core/ApiResult.d.ts +8 -0
  47. package/dist/generated/core/ApiResult.d.ts.map +1 -0
  48. package/dist/generated/core/ApiResult.js +3 -0
  49. package/dist/generated/core/ApiResult.js.map +1 -0
  50. package/dist/generated/core/CancelablePromise.d.ts +27 -0
  51. package/dist/generated/core/CancelablePromise.d.ts.map +1 -0
  52. package/dist/generated/core/CancelablePromise.js +101 -0
  53. package/dist/generated/core/CancelablePromise.js.map +1 -0
  54. package/dist/generated/core/OpenAPI.d.ts +29 -0
  55. package/dist/generated/core/OpenAPI.d.ts.map +1 -0
  56. package/dist/generated/core/OpenAPI.js +35 -0
  57. package/dist/generated/core/OpenAPI.js.map +1 -0
  58. package/dist/generated/core/request.d.ts +33 -0
  59. package/dist/generated/core/request.d.ts.map +1 -0
  60. package/dist/generated/core/request.js +310 -0
  61. package/dist/generated/core/request.js.map +1 -0
  62. package/dist/generated/index.d.ts +7 -0
  63. package/dist/generated/index.d.ts.map +1 -0
  64. package/dist/generated/index.js +29 -0
  65. package/dist/generated/index.js.map +1 -0
  66. package/dist/generated/schemas.gen.d.ts +895 -0
  67. package/dist/generated/schemas.gen.d.ts.map +1 -0
  68. package/dist/generated/schemas.gen.js +903 -0
  69. package/dist/generated/schemas.gen.js.map +1 -0
  70. package/dist/generated/services.gen.d.ts +546 -0
  71. package/dist/generated/services.gen.d.ts.map +1 -0
  72. package/dist/generated/services.gen.js +1393 -0
  73. package/dist/generated/services.gen.js.map +1 -0
  74. package/dist/generated/types.gen.d.ts +1790 -0
  75. package/dist/generated/types.gen.d.ts.map +1 -0
  76. package/dist/generated/types.gen.js +4 -0
  77. package/dist/generated/types.gen.js.map +1 -0
  78. package/dist/index.js +23 -4
  79. package/dist/index.js.map +1 -1
  80. package/dist/utils/api.d.ts +1 -9
  81. package/dist/utils/api.d.ts.map +1 -1
  82. package/dist/utils/api.js +5 -4
  83. package/dist/utils/api.js.map +1 -1
  84. package/dist/utils/error.d.ts +5 -3
  85. package/dist/utils/error.d.ts.map +1 -1
  86. package/dist/utils/error.js +31 -16
  87. package/dist/utils/error.js.map +1 -1
  88. package/dist/utils/output.d.ts +1 -1
  89. package/dist/utils/output.js +2 -2
  90. package/dist/utils/output.js.map +1 -1
  91. package/dist/vcs-client.stub.d.ts +74 -0
  92. package/dist/vcs-client.stub.d.ts.map +1 -0
  93. package/dist/vcs-client.stub.js +40 -0
  94. package/dist/vcs-client.stub.js.map +1 -0
  95. package/package.json +10 -5
  96. package/dist/client.d.ts +0 -9
  97. package/dist/client.d.ts.map +0 -1
  98. package/dist/client.js +0 -23
  99. package/dist/client.js.map +0 -1
  100. package/dist/generated.d.ts +0 -200
  101. package/dist/generated.d.ts.map +0 -1
  102. package/dist/generated.js +0 -131
  103. package/dist/generated.js.map +0 -1
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ticketCommand = ticketCommand;
4
4
  const config_1 = require("../config");
5
- const client_1 = require("../client");
5
+ const OpenAPI_1 = require("../generated/core/OpenAPI");
6
6
  const generated_1 = require("../generated");
7
7
  const output_1 = require("../utils/output");
8
8
  const api_1 = require("../utils/api");
@@ -23,38 +23,32 @@ function ticketCommand(program) {
23
23
  try {
24
24
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
25
25
  if (!ctx.projectSlug) {
26
- (0, output_1.error)('Project not configured. Run: koda init');
27
- process.exit(2);
28
- return;
26
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
29
27
  }
30
28
  if (!ctx.apiKey) {
31
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
32
- process.exit(2);
33
- return;
29
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
34
30
  }
35
- // Validate required options
36
31
  if (!options.type || !options.title) {
37
- (0, output_1.error)('Missing required options: --type and --title are required');
38
- process.exit(3);
32
+ (0, error_1.handleApiError)(new Error('Missing required options: --type and --title are required'), { validationError: true });
39
33
  }
40
34
  const validTypes = ['BUG', 'ENHANCEMENT', 'TASK', 'QUESTION'];
41
35
  if (!validTypes.includes(options.type)) {
42
- (0, output_1.error)(`Invalid type ${options.type}. Valid values: ${validTypes.join(', ')}`);
43
- process.exit(3);
44
- return;
36
+ (0, error_1.handleApiError)(new Error(`Invalid type ${options.type}. Valid values: ${validTypes.join(', ')}`), { validationError: true });
45
37
  }
46
38
  const validPriorities = ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL'];
47
39
  if (options.priority && !validPriorities.includes(options.priority)) {
48
- (0, output_1.error)(`Invalid priority ${options.priority}. Valid values: ${validPriorities.join(', ')}`);
49
- process.exit(3);
50
- return;
51
- }
52
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
53
- const response = await generated_1.TicketsService.create(client, ctx.projectSlug, {
54
- type: options.type,
55
- title: options.title,
56
- description: options.desc,
57
- priority: options.priority,
40
+ (0, error_1.handleApiError)(new Error(`Invalid priority ${options.priority}. Valid values: ${validPriorities.join(', ')}`), { validationError: true });
41
+ }
42
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
43
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
44
+ const response = await (0, generated_1.ticketsControllerCreate)({
45
+ slug: ctx.projectSlug,
46
+ requestBody: {
47
+ type: options.type,
48
+ title: options.title,
49
+ description: options.desc,
50
+ priority: options.priority,
51
+ },
58
52
  });
59
53
  const ticketData = (0, api_1.unwrap)(response);
60
54
  if (options.json) {
@@ -86,18 +80,15 @@ function ticketCommand(program) {
86
80
  try {
87
81
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
88
82
  if (!ctx.projectSlug) {
89
- (0, output_1.error)('Project not configured. Run: koda init');
90
- process.exit(2);
91
- return;
83
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
92
84
  }
93
85
  if (!ctx.apiKey) {
94
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
95
- process.exit(2);
96
- return;
86
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
97
87
  }
98
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
99
- const response = await generated_1.TicketsService.list(client, {
100
- projectSlug: ctx.projectSlug,
88
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
89
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
90
+ const response = await (0, generated_1.ticketsControllerFindAll)({
91
+ slug: ctx.projectSlug,
101
92
  status: options.status,
102
93
  type: options.type,
103
94
  priority: options.priority,
@@ -107,13 +98,13 @@ function ticketCommand(program) {
107
98
  page: parseInt(options.page, 10),
108
99
  });
109
100
  const data = (0, api_1.unwrap)(response);
110
- const items = Array.isArray(data) ? data : data.items || [];
101
+ const items = Array.isArray(data) ? data : (data.items ?? []);
111
102
  if (options.json) {
112
103
  console.log(JSON.stringify(items, null, 2));
113
104
  }
114
105
  else {
115
106
  const rows = items.map((t) => [
116
- `KODA-${t.number}`,
107
+ String(t.ref ?? `KODA-${t.number}`),
117
108
  String(t.type),
118
109
  String(t.priority || ''),
119
110
  String(t.status),
@@ -138,29 +129,26 @@ function ticketCommand(program) {
138
129
  try {
139
130
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
140
131
  if (!ctx.projectSlug) {
141
- (0, output_1.error)('Project not configured. Run: koda init');
142
- process.exit(2);
143
- return;
132
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
144
133
  }
145
134
  if (!ctx.apiKey) {
146
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
147
- process.exit(2);
148
- return;
135
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
149
136
  }
150
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
151
- const response = await generated_1.TicketsService.list(client, {
152
- projectSlug: ctx.projectSlug,
137
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
138
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
139
+ const response = await (0, generated_1.ticketsControllerFindAll)({
140
+ slug: ctx.projectSlug,
153
141
  status: options.status,
154
142
  assignedTo: 'self',
155
143
  });
156
144
  const data = (0, api_1.unwrap)(response);
157
- const items = Array.isArray(data) ? data : data.items || [];
145
+ const items = Array.isArray(data) ? data : (data.items ?? []);
158
146
  if (options.json) {
159
147
  console.log(JSON.stringify(items, null, 2));
160
148
  }
161
149
  else {
162
150
  const rows = items.map((t) => [
163
- `KODA-${t.number}`,
151
+ String(t.ref ?? `KODA-${t.number}`),
164
152
  String(t.type),
165
153
  String(t.priority || ''),
166
154
  String(t.status),
@@ -184,17 +172,14 @@ function ticketCommand(program) {
184
172
  try {
185
173
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
186
174
  if (!ctx.projectSlug) {
187
- (0, output_1.error)('Project not configured. Run: koda init');
188
- process.exit(2);
189
- return;
175
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
190
176
  }
191
177
  if (!ctx.apiKey) {
192
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
193
- process.exit(2);
194
- return;
178
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
195
179
  }
196
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
197
- const response = await generated_1.TicketsService.show(client, ctx.projectSlug, ref);
180
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
181
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
182
+ const response = await (0, generated_1.ticketsControllerFindByRef)({ slug: ctx.projectSlug, ref });
198
183
  const ticketData = (0, api_1.unwrap)(response);
199
184
  if (options.json) {
200
185
  console.log(JSON.stringify(ticketData, null, 2));
@@ -220,6 +205,39 @@ function ticketCommand(program) {
220
205
  console.log(` - ${author} (${comment.type}): ${comment.body}`);
221
206
  }
222
207
  }
208
+ if (ticketData.links && ticketData.links.length > 0) {
209
+ // Group links by linkType
210
+ const branches = ticketData.links.filter(l => l.linkType === 'branch');
211
+ const commits = ticketData.links.filter(l => l.linkType === 'commit');
212
+ const pullRequests = ticketData.links.filter(l => l.linkType === 'pr' || (!l.linkType && l.prNumber));
213
+ if (branches.length > 0) {
214
+ console.log(`\nBranches:`);
215
+ for (const link of branches) {
216
+ console.log(` - ${link.externalRef || link.url}`);
217
+ }
218
+ }
219
+ if (commits.length > 0) {
220
+ console.log(`\nCommits:`);
221
+ for (const link of commits) {
222
+ const sha = link.url.split('/').pop()?.slice(0, 7) || link.url;
223
+ const summary = link.title || link.externalRef || link.url;
224
+ console.log(` - ${sha} - ${summary}`);
225
+ }
226
+ }
227
+ if (pullRequests.length > 0) {
228
+ console.log(`\nPull Requests:`);
229
+ for (const link of pullRequests) {
230
+ let linkStr = ` - ${link.url} (${link.provider})`;
231
+ if (link.externalRef) {
232
+ linkStr += ` [${link.externalRef}]`;
233
+ }
234
+ if (link.prState) {
235
+ linkStr += ` [${link.prState}]`;
236
+ }
237
+ console.log(linkStr);
238
+ }
239
+ }
240
+ }
223
241
  }
224
242
  process.exit(0);
225
243
  }
@@ -232,28 +250,25 @@ function ticketCommand(program) {
232
250
  .description('Verify a ticket (CREATED → VERIFIED)')
233
251
  .option('--project <slug>', 'Project slug')
234
252
  .option('--comment <text>', 'Verification comment')
253
+ .option('--json', 'Output as JSON')
235
254
  .action(async (ref, options) => {
236
255
  try {
237
256
  if (!options.comment) {
238
- (0, output_1.error)('Comment is required');
239
- process.exit(3);
240
- return;
257
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
241
258
  }
242
259
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
243
260
  if (!ctx.projectSlug) {
244
- (0, output_1.error)('Project not configured. Run: koda init');
245
- process.exit(2);
246
- return;
261
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
247
262
  }
248
263
  if (!ctx.apiKey) {
249
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
250
- process.exit(2);
251
- return;
252
- }
253
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
254
- await generated_1.TicketsService.verify(client, ctx.projectSlug, ref, {
255
- body: options.comment,
256
- type: 'VERIFICATION',
264
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
265
+ }
266
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
267
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
268
+ await (0, generated_1.ticketsControllerVerify)({
269
+ slug: ctx.projectSlug,
270
+ ref,
271
+ requestBody: { body: options.comment },
257
272
  });
258
273
  console.log(`✓ Ticket verified successfully`);
259
274
  process.exit(0);
@@ -273,18 +288,14 @@ function ticketCommand(program) {
273
288
  try {
274
289
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
275
290
  if (!ctx.projectSlug) {
276
- (0, output_1.error)('Project not configured. Run: koda init');
277
- process.exit(2);
278
- return;
291
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
279
292
  }
280
293
  if (!ctx.apiKey) {
281
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
282
- process.exit(2);
283
- return;
294
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
284
295
  }
285
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
286
- const agentSlug = options.agent ?? options.to ?? 'self';
287
- const response = await generated_1.TicketsService.assign(client, ctx.projectSlug, ref, { agentSlug });
296
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
297
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
298
+ const response = await (0, generated_1.ticketsControllerAssign)({ slug: ctx.projectSlug, ref });
288
299
  const ticketData = (0, api_1.unwrap)(response);
289
300
  if (options.json) {
290
301
  console.log(JSON.stringify(ticketData, null, 2));
@@ -302,21 +313,19 @@ function ticketCommand(program) {
302
313
  .command('start <ref>')
303
314
  .description('Start a ticket (CREATED or VERIFIED → IN_PROGRESS)')
304
315
  .option('--project <slug>', 'Project slug')
316
+ .option('--json', 'Output as JSON')
305
317
  .action(async (ref, options) => {
306
318
  try {
307
319
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
308
320
  if (!ctx.projectSlug) {
309
- (0, output_1.error)('Project not configured. Run: koda init');
310
- process.exit(2);
311
- return;
321
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
312
322
  }
313
323
  if (!ctx.apiKey) {
314
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
315
- process.exit(2);
316
- return;
324
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
317
325
  }
318
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
319
- await generated_1.TicketsService.start(client, ctx.projectSlug, ref);
326
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
327
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
328
+ await (0, generated_1.ticketsControllerStart)({ slug: ctx.projectSlug, ref });
320
329
  console.log(`✓ Ticket started successfully`);
321
330
  process.exit(0);
322
331
  }
@@ -330,33 +339,26 @@ function ticketCommand(program) {
330
339
  .option('--project <slug>', 'Project slug')
331
340
  .option('--comment <text>', 'Fix report comment')
332
341
  .option('--git-ref <ref>', 'Git reference (e.g. branch or commit)')
342
+ .option('--json', 'Output as JSON')
333
343
  .action(async (ref, options) => {
334
344
  try {
335
345
  if (!options.comment) {
336
- (0, output_1.error)('Comment is required');
337
- process.exit(3);
338
- return;
346
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
339
347
  }
340
348
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
341
349
  if (!ctx.projectSlug) {
342
- (0, output_1.error)('Project not configured. Run: koda init');
343
- process.exit(2);
344
- return;
350
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
345
351
  }
346
352
  if (!ctx.apiKey) {
347
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
348
- process.exit(2);
349
- return;
350
- }
351
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
352
- const payload = {
353
- body: options.comment,
354
- type: 'FIX_REPORT',
355
- };
356
- if (options.gitRef) {
357
- payload.gitRef = options.gitRef;
358
- }
359
- await generated_1.TicketsService.fix(client, ctx.projectSlug, ref, payload);
353
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
354
+ }
355
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
356
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
357
+ await (0, generated_1.ticketsControllerFix)({
358
+ slug: ctx.projectSlug,
359
+ ref,
360
+ requestBody: { body: options.comment },
361
+ });
360
362
  console.log(`✓ Fix submitted successfully`);
361
363
  process.exit(0);
362
364
  }
@@ -371,32 +373,41 @@ function ticketCommand(program) {
371
373
  .option('--comment <text>', 'Review comment')
372
374
  .option('--pass', 'Mark fix as passing (closes ticket)')
373
375
  .option('--fail', 'Mark fix as failing (returns to IN_PROGRESS)')
376
+ .option('--json', 'Output as JSON')
374
377
  .action(async (ref, options) => {
375
378
  try {
376
379
  if (!options.comment) {
377
- (0, output_1.error)('Comment is required');
378
- process.exit(3);
379
- return;
380
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
381
+ }
382
+ if (!options.pass && !options.fail) {
383
+ (0, error_1.handleApiError)(new Error('Specify exactly one of --pass or --fail'), { validationError: true });
384
+ }
385
+ if (options.pass && options.fail) {
386
+ (0, error_1.handleApiError)(new Error('Specify only one of --pass or --fail'), { validationError: true });
380
387
  }
381
388
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
382
389
  if (!ctx.projectSlug) {
383
- (0, output_1.error)('Project not configured. Run: koda init');
384
- process.exit(2);
385
- return;
390
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
386
391
  }
387
392
  if (!ctx.apiKey) {
388
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
389
- process.exit(2);
390
- return;
391
- }
392
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
393
- const status = options.pass ? 'closed' : 'in_progress';
394
- await generated_1.TicketsService.verifyFix(client, ctx.projectSlug, ref, {
395
- body: options.comment,
396
- type: 'REVIEW',
397
- status,
393
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
394
+ }
395
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
396
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
397
+ await (0, generated_1.ticketsControllerVerifyFix)({
398
+ slug: ctx.projectSlug,
399
+ ref,
400
+ requestBody: { body: options.comment },
398
401
  });
399
- console.log(`✓ Fix verification submitted successfully`);
402
+ // The generated client currently does not expose the approve query param.
403
+ // Preserve expected CLI semantics: --pass should conclude with CLOSED.
404
+ if (options.pass) {
405
+ await (0, generated_1.ticketsControllerClose)({ slug: ctx.projectSlug, ref });
406
+ console.log(`✓ Fix verified and ticket closed successfully`);
407
+ }
408
+ else {
409
+ console.log(`✓ Fix verification submitted successfully`);
410
+ }
400
411
  process.exit(0);
401
412
  }
402
413
  catch (err) {
@@ -407,21 +418,19 @@ function ticketCommand(program) {
407
418
  .command('close <ref>')
408
419
  .description('Close a ticket')
409
420
  .option('--project <slug>', 'Project slug')
421
+ .option('--json', 'Output as JSON')
410
422
  .action(async (ref, options) => {
411
423
  try {
412
424
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
413
425
  if (!ctx.projectSlug) {
414
- (0, output_1.error)('Project not configured. Run: koda init');
415
- process.exit(2);
416
- return;
426
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
417
427
  }
418
428
  if (!ctx.apiKey) {
419
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
420
- process.exit(2);
421
- return;
429
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
422
430
  }
423
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
424
- await generated_1.TicketsService.close(client, ctx.projectSlug, ref);
431
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
432
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
433
+ await (0, generated_1.ticketsControllerClose)({ slug: ctx.projectSlug, ref });
425
434
  console.log(`✓ Ticket closed successfully`);
426
435
  process.exit(0);
427
436
  }
@@ -434,28 +443,25 @@ function ticketCommand(program) {
434
443
  .description('Reject a ticket')
435
444
  .option('--project <slug>', 'Project slug')
436
445
  .option('--comment <text>', 'Rejection reason')
446
+ .option('--json', 'Output as JSON')
437
447
  .action(async (ref, options) => {
438
448
  try {
439
449
  if (!options.comment) {
440
- (0, output_1.error)('Comment is required');
441
- process.exit(3);
442
- return;
450
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
443
451
  }
444
452
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
445
453
  if (!ctx.projectSlug) {
446
- (0, output_1.error)('Project not configured. Run: koda init');
447
- process.exit(2);
448
- return;
454
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
449
455
  }
450
456
  if (!ctx.apiKey) {
451
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
452
- process.exit(2);
453
- return;
454
- }
455
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
456
- await generated_1.TicketsService.reject(client, ctx.projectSlug, ref, {
457
- body: options.comment,
458
- type: 'GENERAL',
457
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
458
+ }
459
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
460
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
461
+ await (0, generated_1.ticketsControllerReject)({
462
+ slug: ctx.projectSlug,
463
+ ref,
464
+ requestBody: { body: options.comment },
459
465
  });
460
466
  console.log(`✓ Ticket rejected successfully`);
461
467
  process.exit(0);
@@ -476,24 +482,21 @@ function ticketCommand(program) {
476
482
  try {
477
483
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
478
484
  if (!ctx.projectSlug) {
479
- (0, output_1.error)('Project not configured. Run: koda init');
480
- process.exit(2);
481
- return;
485
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
482
486
  }
483
487
  if (!ctx.apiKey) {
484
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
485
- process.exit(2);
486
- return;
488
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
487
489
  }
488
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
489
- const payload = {};
490
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
491
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
492
+ const requestBody = {};
490
493
  if (options.title)
491
- payload.title = options.title;
494
+ requestBody.title = options.title;
492
495
  if (options.desc)
493
- payload.description = options.desc;
496
+ requestBody.description = options.desc;
494
497
  if (options.priority)
495
- payload.priority = options.priority;
496
- const response = await generated_1.TicketsService.update(client, ctx.projectSlug, ref, payload);
498
+ requestBody.priority = options.priority;
499
+ const response = await (0, generated_1.ticketsControllerUpdate)({ slug: ctx.projectSlug, ref, requestBody });
497
500
  const ticketData = (0, api_1.unwrap)(response);
498
501
  if (options.json) {
499
502
  console.log(JSON.stringify(ticketData, null, 2));
@@ -515,22 +518,18 @@ function ticketCommand(program) {
515
518
  .action(async (ref, options) => {
516
519
  try {
517
520
  if (!options.force) {
518
- (0, output_1.error)(`Deletion requires --force flag.`);
519
- process.exit(1);
521
+ (0, error_1.handleApiError)(new Error('Deletion requires --force flag.'), { validationError: true });
520
522
  }
521
523
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
522
524
  if (!ctx.projectSlug) {
523
- (0, output_1.error)('Project not configured. Run: koda init');
524
- process.exit(2);
525
- return;
525
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
526
526
  }
527
527
  if (!ctx.apiKey) {
528
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
529
- process.exit(2);
530
- return;
528
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
531
529
  }
532
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
533
- await generated_1.TicketsService.delete(client, ctx.projectSlug, ref);
530
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
531
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
532
+ await (0, generated_1.ticketsControllerSoftDelete)({ slug: ctx.projectSlug, ref });
534
533
  console.log(`✓ Ticket deleted successfully`);
535
534
  process.exit(0);
536
535
  }
@@ -548,17 +547,18 @@ function ticketCommand(program) {
548
547
  try {
549
548
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
550
549
  if (!ctx.projectSlug) {
551
- (0, output_1.error)('Project not configured. Run: koda init');
552
- process.exit(2);
553
- return;
550
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
554
551
  }
555
552
  if (!ctx.apiKey) {
556
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
557
- process.exit(2);
558
- return;
559
- }
560
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
561
- const response = await generated_1.TicketLinksService.create(client, ctx.projectSlug, ref, { url: options.url });
553
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
554
+ }
555
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
556
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
557
+ const response = await (0, generated_1.ticketLinksControllerCreate)({
558
+ slug: ctx.projectSlug,
559
+ ref,
560
+ requestBody: { url: options.url },
561
+ });
562
562
  const linkData = (0, api_1.unwrap)(response);
563
563
  if (options.json) {
564
564
  console.log(JSON.stringify(linkData, null, 2));
@@ -582,25 +582,21 @@ function ticketCommand(program) {
582
582
  try {
583
583
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
584
584
  if (!ctx.projectSlug) {
585
- (0, output_1.error)('Project not configured. Run: koda init');
586
- process.exit(2);
587
- return;
585
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
588
586
  }
589
587
  if (!ctx.apiKey) {
590
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
591
- process.exit(2);
592
- return;
588
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
593
589
  }
594
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
595
- const listResponse = await generated_1.TicketLinksService.list(client, ctx.projectSlug, ref);
590
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
591
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
592
+ const listResponse = await (0, generated_1.ticketLinksControllerFindAll)({ slug: ctx.projectSlug, ref });
596
593
  const links = (0, api_1.unwrap)(listResponse);
597
594
  const match = links.find((l) => l.url === options.url);
598
595
  if (!match) {
599
596
  console.log(`No link found for ${options.url}`);
600
597
  process.exit(1);
601
- return;
602
598
  }
603
- await generated_1.TicketLinksService.delete(client, ctx.projectSlug, ref, match.id);
599
+ await (0, generated_1.ticketLinksControllerRemove)({ slug: ctx.projectSlug, ref, linkId: match.id });
604
600
  process.exit(0);
605
601
  }
606
602
  catch (err) {
@@ -617,17 +613,18 @@ function ticketCommand(program) {
617
613
  try {
618
614
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
619
615
  if (!ctx.projectSlug) {
620
- (0, output_1.error)('Project not configured. Run: koda init');
621
- process.exit(2);
622
- return;
616
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
623
617
  }
624
618
  if (!ctx.apiKey) {
625
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
626
- process.exit(2);
627
- return;
628
- }
629
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
630
- await generated_1.LabelsService.addToTicket(client, ctx.projectSlug, ref, options.label);
619
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
620
+ }
621
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
622
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
623
+ await (0, generated_1.labelsControllerAssignLabelFromHttp)({
624
+ slug: ctx.projectSlug,
625
+ ref,
626
+ requestBody: { labelId: options.label },
627
+ });
631
628
  console.log(`✓ Label attached to ticket ${ref}`);
632
629
  process.exit(0);
633
630
  }
@@ -645,17 +642,18 @@ function ticketCommand(program) {
645
642
  try {
646
643
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
647
644
  if (!ctx.projectSlug) {
648
- (0, output_1.error)('Project not configured. Run: koda init');
649
- process.exit(2);
650
- return;
645
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
651
646
  }
652
647
  if (!ctx.apiKey) {
653
- (0, output_1.error)('API key or URL not configured. Run: koda login --api-key <key>');
654
- process.exit(2);
655
- return;
656
- }
657
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
658
- await generated_1.LabelsService.removeFromTicket(client, ctx.projectSlug, ref, options.label);
648
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
649
+ }
650
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
651
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
652
+ await (0, generated_1.labelsControllerRemoveLabelFromHttp)({
653
+ slug: ctx.projectSlug,
654
+ ref,
655
+ labelId: options.label,
656
+ });
659
657
  console.log(`✓ Label detached from ticket ${ref}`);
660
658
  process.exit(0);
661
659
  }