@nathapp/koda-cli 0.2.4 → 0.3.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 (91) 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 +10 -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 +25 -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 +22 -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 +34 -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 +166 -201
  25. package/dist/commands/ticket.js.map +1 -1
  26. package/dist/config.d.ts +1 -0
  27. package/dist/config.d.ts.map +1 -1
  28. package/dist/config.js +2 -2
  29. package/dist/config.js.map +1 -1
  30. package/dist/generated/core/ApiError.d.ts +11 -0
  31. package/dist/generated/core/ApiError.d.ts.map +1 -0
  32. package/dist/generated/core/ApiError.js +21 -0
  33. package/dist/generated/core/ApiError.js.map +1 -0
  34. package/dist/generated/core/ApiRequestOptions.d.ts +14 -0
  35. package/dist/generated/core/ApiRequestOptions.d.ts.map +1 -0
  36. package/dist/generated/core/ApiRequestOptions.js +3 -0
  37. package/dist/generated/core/ApiRequestOptions.js.map +1 -0
  38. package/dist/generated/core/ApiResult.d.ts +8 -0
  39. package/dist/generated/core/ApiResult.d.ts.map +1 -0
  40. package/dist/generated/core/ApiResult.js +3 -0
  41. package/dist/generated/core/ApiResult.js.map +1 -0
  42. package/dist/generated/core/CancelablePromise.d.ts +27 -0
  43. package/dist/generated/core/CancelablePromise.d.ts.map +1 -0
  44. package/dist/generated/core/CancelablePromise.js +101 -0
  45. package/dist/generated/core/CancelablePromise.js.map +1 -0
  46. package/dist/generated/core/OpenAPI.d.ts +29 -0
  47. package/dist/generated/core/OpenAPI.d.ts.map +1 -0
  48. package/dist/generated/core/OpenAPI.js +35 -0
  49. package/dist/generated/core/OpenAPI.js.map +1 -0
  50. package/dist/generated/core/request.d.ts +33 -0
  51. package/dist/generated/core/request.d.ts.map +1 -0
  52. package/dist/generated/core/request.js +310 -0
  53. package/dist/generated/core/request.js.map +1 -0
  54. package/dist/generated/index.d.ts +7 -0
  55. package/dist/generated/index.d.ts.map +1 -0
  56. package/dist/generated/index.js +29 -0
  57. package/dist/generated/index.js.map +1 -0
  58. package/dist/generated/schemas.gen.d.ts +723 -0
  59. package/dist/generated/schemas.gen.d.ts.map +1 -0
  60. package/dist/generated/schemas.gen.js +731 -0
  61. package/dist/generated/schemas.gen.js.map +1 -0
  62. package/dist/generated/services.gen.d.ts +474 -0
  63. package/dist/generated/services.gen.d.ts.map +1 -0
  64. package/dist/generated/services.gen.js +1218 -0
  65. package/dist/generated/services.gen.js.map +1 -0
  66. package/dist/generated/types.gen.d.ts +1586 -0
  67. package/dist/generated/types.gen.d.ts.map +1 -0
  68. package/dist/generated/types.gen.js +4 -0
  69. package/dist/generated/types.gen.js.map +1 -0
  70. package/dist/index.js +20 -4
  71. package/dist/index.js.map +1 -1
  72. package/dist/utils/api.d.ts +1 -9
  73. package/dist/utils/api.d.ts.map +1 -1
  74. package/dist/utils/api.js +5 -4
  75. package/dist/utils/api.js.map +1 -1
  76. package/dist/utils/error.d.ts +5 -3
  77. package/dist/utils/error.d.ts.map +1 -1
  78. package/dist/utils/error.js +31 -16
  79. package/dist/utils/error.js.map +1 -1
  80. package/dist/utils/output.d.ts +1 -1
  81. package/dist/utils/output.js +2 -2
  82. package/dist/utils/output.js.map +1 -1
  83. package/package.json +10 -5
  84. package/dist/client.d.ts +0 -9
  85. package/dist/client.d.ts.map +0 -1
  86. package/dist/client.js +0 -23
  87. package/dist/client.js.map +0 -1
  88. package/dist/generated.d.ts +0 -200
  89. package/dist/generated.d.ts.map +0 -1
  90. package/dist/generated.js +0 -131
  91. 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));
@@ -232,28 +217,25 @@ function ticketCommand(program) {
232
217
  .description('Verify a ticket (CREATED → VERIFIED)')
233
218
  .option('--project <slug>', 'Project slug')
234
219
  .option('--comment <text>', 'Verification comment')
220
+ .option('--json', 'Output as JSON')
235
221
  .action(async (ref, options) => {
236
222
  try {
237
223
  if (!options.comment) {
238
- (0, output_1.error)('Comment is required');
239
- process.exit(3);
240
- return;
224
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
241
225
  }
242
226
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
243
227
  if (!ctx.projectSlug) {
244
- (0, output_1.error)('Project not configured. Run: koda init');
245
- process.exit(2);
246
- return;
228
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
247
229
  }
248
230
  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',
231
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
232
+ }
233
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
234
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
235
+ await (0, generated_1.ticketsControllerVerify)({
236
+ slug: ctx.projectSlug,
237
+ ref,
238
+ requestBody: { body: options.comment },
257
239
  });
258
240
  console.log(`✓ Ticket verified successfully`);
259
241
  process.exit(0);
@@ -273,18 +255,14 @@ function ticketCommand(program) {
273
255
  try {
274
256
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
275
257
  if (!ctx.projectSlug) {
276
- (0, output_1.error)('Project not configured. Run: koda init');
277
- process.exit(2);
278
- return;
258
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
279
259
  }
280
260
  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;
261
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
284
262
  }
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 });
263
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
264
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
265
+ const response = await (0, generated_1.ticketsControllerAssign)({ slug: ctx.projectSlug, ref });
288
266
  const ticketData = (0, api_1.unwrap)(response);
289
267
  if (options.json) {
290
268
  console.log(JSON.stringify(ticketData, null, 2));
@@ -302,21 +280,19 @@ function ticketCommand(program) {
302
280
  .command('start <ref>')
303
281
  .description('Start a ticket (CREATED or VERIFIED → IN_PROGRESS)')
304
282
  .option('--project <slug>', 'Project slug')
283
+ .option('--json', 'Output as JSON')
305
284
  .action(async (ref, options) => {
306
285
  try {
307
286
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
308
287
  if (!ctx.projectSlug) {
309
- (0, output_1.error)('Project not configured. Run: koda init');
310
- process.exit(2);
311
- return;
288
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
312
289
  }
313
290
  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;
291
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
317
292
  }
318
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
319
- await generated_1.TicketsService.start(client, ctx.projectSlug, ref);
293
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
294
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
295
+ await (0, generated_1.ticketsControllerStart)({ slug: ctx.projectSlug, ref });
320
296
  console.log(`✓ Ticket started successfully`);
321
297
  process.exit(0);
322
298
  }
@@ -330,33 +306,26 @@ function ticketCommand(program) {
330
306
  .option('--project <slug>', 'Project slug')
331
307
  .option('--comment <text>', 'Fix report comment')
332
308
  .option('--git-ref <ref>', 'Git reference (e.g. branch or commit)')
309
+ .option('--json', 'Output as JSON')
333
310
  .action(async (ref, options) => {
334
311
  try {
335
312
  if (!options.comment) {
336
- (0, output_1.error)('Comment is required');
337
- process.exit(3);
338
- return;
313
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
339
314
  }
340
315
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
341
316
  if (!ctx.projectSlug) {
342
- (0, output_1.error)('Project not configured. Run: koda init');
343
- process.exit(2);
344
- return;
317
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
345
318
  }
346
319
  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);
320
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
321
+ }
322
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
323
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
324
+ await (0, generated_1.ticketsControllerFix)({
325
+ slug: ctx.projectSlug,
326
+ ref,
327
+ requestBody: { body: options.comment },
328
+ });
360
329
  console.log(`✓ Fix submitted successfully`);
361
330
  process.exit(0);
362
331
  }
@@ -371,32 +340,41 @@ function ticketCommand(program) {
371
340
  .option('--comment <text>', 'Review comment')
372
341
  .option('--pass', 'Mark fix as passing (closes ticket)')
373
342
  .option('--fail', 'Mark fix as failing (returns to IN_PROGRESS)')
343
+ .option('--json', 'Output as JSON')
374
344
  .action(async (ref, options) => {
375
345
  try {
376
346
  if (!options.comment) {
377
- (0, output_1.error)('Comment is required');
378
- process.exit(3);
379
- return;
347
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
348
+ }
349
+ if (!options.pass && !options.fail) {
350
+ (0, error_1.handleApiError)(new Error('Specify exactly one of --pass or --fail'), { validationError: true });
351
+ }
352
+ if (options.pass && options.fail) {
353
+ (0, error_1.handleApiError)(new Error('Specify only one of --pass or --fail'), { validationError: true });
380
354
  }
381
355
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
382
356
  if (!ctx.projectSlug) {
383
- (0, output_1.error)('Project not configured. Run: koda init');
384
- process.exit(2);
385
- return;
357
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
386
358
  }
387
359
  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,
360
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
361
+ }
362
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
363
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
364
+ await (0, generated_1.ticketsControllerVerifyFix)({
365
+ slug: ctx.projectSlug,
366
+ ref,
367
+ requestBody: { body: options.comment },
398
368
  });
399
- console.log(`✓ Fix verification submitted successfully`);
369
+ // The generated client currently does not expose the approve query param.
370
+ // Preserve expected CLI semantics: --pass should conclude with CLOSED.
371
+ if (options.pass) {
372
+ await (0, generated_1.ticketsControllerClose)({ slug: ctx.projectSlug, ref });
373
+ console.log(`✓ Fix verified and ticket closed successfully`);
374
+ }
375
+ else {
376
+ console.log(`✓ Fix verification submitted successfully`);
377
+ }
400
378
  process.exit(0);
401
379
  }
402
380
  catch (err) {
@@ -407,21 +385,19 @@ function ticketCommand(program) {
407
385
  .command('close <ref>')
408
386
  .description('Close a ticket')
409
387
  .option('--project <slug>', 'Project slug')
388
+ .option('--json', 'Output as JSON')
410
389
  .action(async (ref, options) => {
411
390
  try {
412
391
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
413
392
  if (!ctx.projectSlug) {
414
- (0, output_1.error)('Project not configured. Run: koda init');
415
- process.exit(2);
416
- return;
393
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
417
394
  }
418
395
  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;
396
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
422
397
  }
423
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
424
- await generated_1.TicketsService.close(client, ctx.projectSlug, ref);
398
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
399
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
400
+ await (0, generated_1.ticketsControllerClose)({ slug: ctx.projectSlug, ref });
425
401
  console.log(`✓ Ticket closed successfully`);
426
402
  process.exit(0);
427
403
  }
@@ -434,28 +410,25 @@ function ticketCommand(program) {
434
410
  .description('Reject a ticket')
435
411
  .option('--project <slug>', 'Project slug')
436
412
  .option('--comment <text>', 'Rejection reason')
413
+ .option('--json', 'Output as JSON')
437
414
  .action(async (ref, options) => {
438
415
  try {
439
416
  if (!options.comment) {
440
- (0, output_1.error)('Comment is required');
441
- process.exit(3);
442
- return;
417
+ (0, error_1.handleApiError)(new Error('Comment is required'), { validationError: true });
443
418
  }
444
419
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
445
420
  if (!ctx.projectSlug) {
446
- (0, output_1.error)('Project not configured. Run: koda init');
447
- process.exit(2);
448
- return;
421
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
449
422
  }
450
423
  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',
424
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
425
+ }
426
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
427
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
428
+ await (0, generated_1.ticketsControllerReject)({
429
+ slug: ctx.projectSlug,
430
+ ref,
431
+ requestBody: { body: options.comment },
459
432
  });
460
433
  console.log(`✓ Ticket rejected successfully`);
461
434
  process.exit(0);
@@ -476,24 +449,21 @@ function ticketCommand(program) {
476
449
  try {
477
450
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
478
451
  if (!ctx.projectSlug) {
479
- (0, output_1.error)('Project not configured. Run: koda init');
480
- process.exit(2);
481
- return;
452
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
482
453
  }
483
454
  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;
455
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
487
456
  }
488
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
489
- const payload = {};
457
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
458
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
459
+ const requestBody = {};
490
460
  if (options.title)
491
- payload.title = options.title;
461
+ requestBody.title = options.title;
492
462
  if (options.desc)
493
- payload.description = options.desc;
463
+ requestBody.description = options.desc;
494
464
  if (options.priority)
495
- payload.priority = options.priority;
496
- const response = await generated_1.TicketsService.update(client, ctx.projectSlug, ref, payload);
465
+ requestBody.priority = options.priority;
466
+ const response = await (0, generated_1.ticketsControllerUpdate)({ slug: ctx.projectSlug, ref, requestBody });
497
467
  const ticketData = (0, api_1.unwrap)(response);
498
468
  if (options.json) {
499
469
  console.log(JSON.stringify(ticketData, null, 2));
@@ -515,22 +485,18 @@ function ticketCommand(program) {
515
485
  .action(async (ref, options) => {
516
486
  try {
517
487
  if (!options.force) {
518
- (0, output_1.error)(`Deletion requires --force flag.`);
519
- process.exit(1);
488
+ (0, error_1.handleApiError)(new Error('Deletion requires --force flag.'), { validationError: true });
520
489
  }
521
490
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
522
491
  if (!ctx.projectSlug) {
523
- (0, output_1.error)('Project not configured. Run: koda init');
524
- process.exit(2);
525
- return;
492
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
526
493
  }
527
494
  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;
495
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
531
496
  }
532
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
533
- await generated_1.TicketsService.delete(client, ctx.projectSlug, ref);
497
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
498
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
499
+ await (0, generated_1.ticketsControllerSoftDelete)({ slug: ctx.projectSlug, ref });
534
500
  console.log(`✓ Ticket deleted successfully`);
535
501
  process.exit(0);
536
502
  }
@@ -548,17 +514,18 @@ function ticketCommand(program) {
548
514
  try {
549
515
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
550
516
  if (!ctx.projectSlug) {
551
- (0, output_1.error)('Project not configured. Run: koda init');
552
- process.exit(2);
553
- return;
517
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
554
518
  }
555
519
  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 });
520
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
521
+ }
522
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
523
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
524
+ const response = await (0, generated_1.ticketLinksControllerCreate)({
525
+ slug: ctx.projectSlug,
526
+ ref,
527
+ requestBody: { url: options.url },
528
+ });
562
529
  const linkData = (0, api_1.unwrap)(response);
563
530
  if (options.json) {
564
531
  console.log(JSON.stringify(linkData, null, 2));
@@ -582,25 +549,21 @@ function ticketCommand(program) {
582
549
  try {
583
550
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
584
551
  if (!ctx.projectSlug) {
585
- (0, output_1.error)('Project not configured. Run: koda init');
586
- process.exit(2);
587
- return;
552
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
588
553
  }
589
554
  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;
555
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
593
556
  }
594
- const client = (0, client_1.configureClient)(ctx.apiUrl, ctx.apiKey);
595
- const listResponse = await generated_1.TicketLinksService.list(client, ctx.projectSlug, ref);
557
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
558
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
559
+ const listResponse = await (0, generated_1.ticketLinksControllerFindAll)({ slug: ctx.projectSlug, ref });
596
560
  const links = (0, api_1.unwrap)(listResponse);
597
561
  const match = links.find((l) => l.url === options.url);
598
562
  if (!match) {
599
563
  console.log(`No link found for ${options.url}`);
600
564
  process.exit(1);
601
- return;
602
565
  }
603
- await generated_1.TicketLinksService.delete(client, ctx.projectSlug, ref, match.id);
566
+ await (0, generated_1.ticketLinksControllerRemove)({ slug: ctx.projectSlug, ref, linkId: match.id });
604
567
  process.exit(0);
605
568
  }
606
569
  catch (err) {
@@ -617,17 +580,18 @@ function ticketCommand(program) {
617
580
  try {
618
581
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
619
582
  if (!ctx.projectSlug) {
620
- (0, output_1.error)('Project not configured. Run: koda init');
621
- process.exit(2);
622
- return;
583
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
623
584
  }
624
585
  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);
586
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
587
+ }
588
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
589
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
590
+ await (0, generated_1.labelsControllerAssignLabelFromHttp)({
591
+ slug: ctx.projectSlug,
592
+ ref,
593
+ requestBody: { labelId: options.label },
594
+ });
631
595
  console.log(`✓ Label attached to ticket ${ref}`);
632
596
  process.exit(0);
633
597
  }
@@ -645,17 +609,18 @@ function ticketCommand(program) {
645
609
  try {
646
610
  const ctx = await (0, config_1.resolveContext)({ projectSlug: options.project });
647
611
  if (!ctx.projectSlug) {
648
- (0, output_1.error)('Project not configured. Run: koda init');
649
- process.exit(2);
650
- return;
612
+ (0, error_1.handleApiError)(new Error('Project not configured. Run: koda init'), { configError: true });
651
613
  }
652
614
  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);
615
+ (0, error_1.handleApiError)(new Error('API key or URL not configured. Run: koda login --api-key <key>'), { configError: true });
616
+ }
617
+ OpenAPI_1.OpenAPI.BASE = ctx.apiUrl.replace(/\/api\/?$/, '');
618
+ OpenAPI_1.OpenAPI.TOKEN = ctx.apiKey;
619
+ await (0, generated_1.labelsControllerRemoveLabelFromHttp)({
620
+ slug: ctx.projectSlug,
621
+ ref,
622
+ labelId: options.label,
623
+ });
659
624
  console.log(`✓ Label detached from ticket ${ref}`);
660
625
  process.exit(0);
661
626
  }