codmir 0.4.1 → 0.6.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.
@@ -1,343 +0,0 @@
1
- // src/client.ts
2
- var CodmirClient = class {
3
- constructor(config) {
4
- this.config = {
5
- apiKey: config.apiKey || "",
6
- baseUrl: config.baseUrl || "https://codmir.com",
7
- timeout: config.timeout || 3e4,
8
- headers: config.headers || {}
9
- };
10
- this.tickets = new TicketsAPI(this.config);
11
- this.testCases = new TestCasesAPI(this.config);
12
- this.testing = new TestingAPI(this.config);
13
- }
14
- /**
15
- * Make an HTTP request to the codmir API
16
- */
17
- async request(method, path, body) {
18
- const url = `${this.config.baseUrl}${path}`;
19
- const headers = {
20
- "Content-Type": "application/json",
21
- ...this.config.headers
22
- };
23
- if (this.config.apiKey) {
24
- headers["X-API-Key"] = this.config.apiKey;
25
- }
26
- const controller = new AbortController();
27
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
28
- try {
29
- const response = await fetch(url, {
30
- method,
31
- headers,
32
- body: body ? JSON.stringify(body) : void 0,
33
- signal: controller.signal
34
- });
35
- clearTimeout(timeoutId);
36
- if (!response.ok) {
37
- const errorData = await response.json().catch(() => ({}));
38
- throw this.createError(
39
- errorData.error || `HTTP ${response.status}: ${response.statusText}`,
40
- response.status,
41
- errorData
42
- );
43
- }
44
- if (response.status === 204) {
45
- return {};
46
- }
47
- return await response.json();
48
- } catch (error) {
49
- clearTimeout(timeoutId);
50
- if (error.name === "AbortError") {
51
- throw this.createError("Request timeout", 408);
52
- }
53
- if (error instanceof Error && "statusCode" in error) {
54
- throw error;
55
- }
56
- throw this.createError(
57
- error.message || "Network error occurred",
58
- void 0,
59
- error
60
- );
61
- }
62
- }
63
- createError(message, statusCode, response) {
64
- const error = new Error(message);
65
- error.name = "CodmirError";
66
- error.statusCode = statusCode;
67
- error.response = response;
68
- return error;
69
- }
70
- };
71
- var TicketsAPI = class {
72
- constructor(config) {
73
- this.config = config;
74
- }
75
- async request(method, path, body) {
76
- const url = `${this.config.baseUrl}${path}`;
77
- const headers = {
78
- "Content-Type": "application/json",
79
- ...this.config.headers
80
- };
81
- if (this.config.apiKey) {
82
- headers["X-API-Key"] = this.config.apiKey;
83
- }
84
- const controller = new AbortController();
85
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
86
- try {
87
- const response = await fetch(url, {
88
- method,
89
- headers,
90
- body: body ? JSON.stringify(body) : void 0,
91
- signal: controller.signal
92
- });
93
- clearTimeout(timeoutId);
94
- if (!response.ok) {
95
- const errorData = await response.json().catch(() => ({}));
96
- const error = new Error(errorData.error || `HTTP ${response.status}`);
97
- error.statusCode = response.status;
98
- error.response = errorData;
99
- throw error;
100
- }
101
- if (response.status === 204) {
102
- return {};
103
- }
104
- return await response.json();
105
- } catch (error) {
106
- clearTimeout(timeoutId);
107
- if (error.name === "AbortError") {
108
- const timeoutError = new Error("Request timeout");
109
- timeoutError.statusCode = 408;
110
- throw timeoutError;
111
- }
112
- throw error;
113
- }
114
- }
115
- /**
116
- * Create a ticket in a board
117
- *
118
- * @param projectId - The project ID
119
- * @param boardId - The board ID
120
- * @param data - Ticket data
121
- */
122
- async createInBoard(projectId, boardId, data) {
123
- const response = await this.request(
124
- "POST",
125
- `/api/project/${projectId}/board/${boardId}/ticket`,
126
- data
127
- );
128
- return response.ticket;
129
- }
130
- /**
131
- * Create a ticket in a workspace
132
- *
133
- * @param projectId - The project ID
134
- * @param workspaceId - The workspace ID
135
- * @param data - Ticket data
136
- */
137
- async createInWorkspace(projectId, workspaceId, data) {
138
- return this.request(
139
- "POST",
140
- `/api/project/${projectId}/workspaces/${workspaceId}/tickets`,
141
- data
142
- );
143
- }
144
- /**
145
- * Alias for createInBoard - creates a ticket in a board
146
- */
147
- async create(projectId, boardId, data) {
148
- return this.createInBoard(projectId, boardId, data);
149
- }
150
- };
151
- var TestCasesAPI = class {
152
- constructor(config) {
153
- this.config = config;
154
- }
155
- async request(method, path, body) {
156
- const url = `${this.config.baseUrl}${path}`;
157
- const headers = {
158
- "Content-Type": "application/json",
159
- ...this.config.headers
160
- };
161
- if (this.config.apiKey) {
162
- headers["X-API-Key"] = this.config.apiKey;
163
- }
164
- const controller = new AbortController();
165
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
166
- try {
167
- const response = await fetch(url, {
168
- method,
169
- headers,
170
- body: body ? JSON.stringify(body) : void 0,
171
- signal: controller.signal
172
- });
173
- clearTimeout(timeoutId);
174
- if (!response.ok) {
175
- const errorData = await response.json().catch(() => ({}));
176
- const error = new Error(errorData.error || `HTTP ${response.status}`);
177
- error.statusCode = response.status;
178
- error.response = errorData;
179
- throw error;
180
- }
181
- if (response.status === 204) {
182
- return {};
183
- }
184
- return await response.json();
185
- } catch (error) {
186
- clearTimeout(timeoutId);
187
- if (error.name === "AbortError") {
188
- const timeoutError = new Error("Request timeout");
189
- timeoutError.statusCode = 408;
190
- throw timeoutError;
191
- }
192
- throw error;
193
- }
194
- }
195
- /**
196
- * List all test cases for a project
197
- *
198
- * @param projectId - The project ID
199
- */
200
- async list(projectId) {
201
- const response = await this.request(
202
- "GET",
203
- `/api/project/${projectId}/test-cases`
204
- );
205
- return response.data || [];
206
- }
207
- /**
208
- * Get a specific test case by ID
209
- *
210
- * @param projectId - The project ID
211
- * @param testCaseId - The test case ID (numeric UD)
212
- */
213
- async get(projectId, testCaseId) {
214
- const response = await this.request(
215
- "GET",
216
- `/api/project/${projectId}/test-cases/${testCaseId}`
217
- );
218
- if (!response.data) {
219
- throw new Error("Test case not found");
220
- }
221
- return response.data;
222
- }
223
- /**
224
- * Create a new test case
225
- *
226
- * @param projectId - The project ID
227
- * @param data - Test case data
228
- */
229
- async create(projectId, data) {
230
- const response = await this.request(
231
- "POST",
232
- `/api/project/${projectId}/test-cases`,
233
- data
234
- );
235
- if (!response.data) {
236
- throw new Error("Failed to create test case");
237
- }
238
- return response.data;
239
- }
240
- /**
241
- * Update an existing test case
242
- *
243
- * @param projectId - The project ID
244
- * @param testCaseId - The test case ID (numeric UD)
245
- * @param data - Test case update data
246
- */
247
- async update(projectId, testCaseId, data) {
248
- const response = await this.request(
249
- "PATCH",
250
- `/api/project/${projectId}/test-cases/${testCaseId}`,
251
- data
252
- );
253
- if (!response.data) {
254
- throw new Error("Failed to update test case");
255
- }
256
- return response.data;
257
- }
258
- /**
259
- * Delete a test case
260
- *
261
- * @param projectId - The project ID
262
- * @param testCaseId - The test case ID (numeric UD)
263
- */
264
- async delete(projectId, testCaseId) {
265
- await this.request(
266
- "DELETE",
267
- `/api/project/${projectId}/test-cases/${testCaseId}`
268
- );
269
- }
270
- };
271
- var TestingAPI = class {
272
- constructor(config) {
273
- this.config = config;
274
- }
275
- async request(method, path, body) {
276
- const url = `${this.config.baseUrl}${path}`;
277
- const headers = {
278
- "Content-Type": "application/json",
279
- ...this.config.headers
280
- };
281
- if (this.config.apiKey) {
282
- headers["X-API-Key"] = this.config.apiKey;
283
- }
284
- const controller = new AbortController();
285
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
286
- try {
287
- const response = await fetch(url, {
288
- method,
289
- headers,
290
- body: body ? JSON.stringify(body) : void 0,
291
- signal: controller.signal
292
- });
293
- clearTimeout(timeoutId);
294
- if (!response.ok) {
295
- const errorData = await response.json().catch(() => ({}));
296
- const error = new Error(errorData.error || `HTTP ${response.status}`);
297
- error.statusCode = response.status;
298
- error.response = errorData;
299
- throw error;
300
- }
301
- if (response.status === 204) {
302
- return {};
303
- }
304
- return await response.json();
305
- } catch (error) {
306
- clearTimeout(timeoutId);
307
- if (error.name === "AbortError") {
308
- const timeoutError = new Error("Request timeout");
309
- timeoutError.statusCode = 408;
310
- throw timeoutError;
311
- }
312
- throw error;
313
- }
314
- }
315
- async submitTestRun(payload) {
316
- return this.request("POST", "/api/testing/test-runs", payload);
317
- }
318
- async listTestRuns(projectId, options) {
319
- const params = new URLSearchParams({ projectId });
320
- if (options?.limit) params.set("limit", String(options.limit));
321
- if (options?.suite) params.set("suite", options.suite);
322
- const response = await this.request(
323
- "GET",
324
- `/api/testing/test-runs?${params.toString()}`
325
- );
326
- return response.runs || [];
327
- }
328
- async requestCoverageInsight(payload) {
329
- return this.request("POST", "/api/testing/coverage-insight", payload);
330
- }
331
- async listCoverageInsights(projectId, limit = 5) {
332
- const params = new URLSearchParams({ projectId, limit: String(limit) });
333
- const response = await this.request(
334
- "GET",
335
- `/api/testing/coverage-insight?${params.toString()}`
336
- );
337
- return response.reports || [];
338
- }
339
- };
340
-
341
- export {
342
- CodmirClient
343
- };
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
@@ -1 +0,0 @@
1
- #!/usr/bin/env node