@smartbear/mcp 0.2.2 → 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.
@@ -1,5 +1,25 @@
1
1
  import { BaseAPI } from './base.js';
2
2
  import { toQueryString } from './filters.js';
3
+ export const ErrorOperations = [
4
+ 'override_severity',
5
+ 'assign',
6
+ 'create_issue',
7
+ 'link_issue',
8
+ 'unlink_issue',
9
+ 'open',
10
+ 'snooze',
11
+ 'fix',
12
+ 'ignore',
13
+ 'delete',
14
+ 'discard',
15
+ 'undiscard'
16
+ ];
17
+ export const ReopenConditions = [
18
+ 'occurs_after',
19
+ 'n_occurrences_in_m_hours',
20
+ 'n_additional_occurrences',
21
+ 'n_additional_users'
22
+ ];
3
23
  // --- API Class ---
4
24
  export class ErrorAPI extends BaseAPI {
5
25
  constructor(configuration) {
@@ -41,6 +61,17 @@ export class ErrorAPI extends BaseAPI {
41
61
  url,
42
62
  }));
43
63
  }
64
+ /**
65
+ * List the Events on a Project
66
+ * GET /projects/{project_id}/events
67
+ */
68
+ async listEventsOnProject(projectId, queryString = '') {
69
+ const url = `/projects/${projectId}/events${queryString}`;
70
+ return await this.request({
71
+ method: 'GET',
72
+ url,
73
+ });
74
+ }
44
75
  /**
45
76
  * View an Event by ID
46
77
  * GET /projects/{project_id}/events/{event_id}
@@ -72,4 +103,54 @@ export class ErrorAPI extends BaseAPI {
72
103
  url,
73
104
  }));
74
105
  }
106
+ /**
107
+ * Update an Error on a Project
108
+ * PATCH /projects/{project_id}/errors/{error_id}
109
+ */
110
+ async updateErrorOnProject(projectId, errorId, data, options = {}) {
111
+ const params = new URLSearchParams();
112
+ for (const [key, value] of Object.entries(options)) {
113
+ if (value !== undefined)
114
+ params.append(key, String(value));
115
+ }
116
+ const url = params.toString()
117
+ ? `/projects/${projectId}/errors/${errorId}?${params}`
118
+ : `/projects/${projectId}/errors/${errorId}`;
119
+ return (await this.request({
120
+ method: 'PATCH',
121
+ url,
122
+ body: data,
123
+ }));
124
+ }
125
+ /**
126
+ * List Pivots on an Error
127
+ * GET /projects/{project_id}/errors/{error_id}/pivots
128
+ */
129
+ async listErrorPivots(projectId, errorId, options = {}) {
130
+ const params = new URLSearchParams();
131
+ if (options.filters) {
132
+ const filterParams = new URLSearchParams(toQueryString(options.filters));
133
+ filterParams.forEach((value, key) => {
134
+ params.append(key, value);
135
+ });
136
+ }
137
+ if (options.summary_size !== undefined) {
138
+ params.append('summary_size', options.summary_size.toString());
139
+ }
140
+ if (options.pivots && options.pivots.length > 0) {
141
+ options.pivots.forEach(pivot => {
142
+ params.append('pivots[]', pivot);
143
+ });
144
+ }
145
+ if (options.per_page !== undefined) {
146
+ params.append('per_page', options.per_page.toString());
147
+ }
148
+ const url = params.toString()
149
+ ? `/projects/${projectId}/errors/${errorId}/pivots?${params}`
150
+ : `/projects/${projectId}/errors/${errorId}/pivots`;
151
+ return await this.request({
152
+ method: 'GET',
153
+ url,
154
+ });
155
+ }
75
156
  }
@@ -23,6 +23,24 @@ export class ProjectAPI extends BaseAPI {
23
23
  url,
24
24
  });
25
25
  // Only return allowed fields
26
- return pickFieldsFromArray(data, ProjectAPI.eventFieldFields);
26
+ return {
27
+ ...data,
28
+ body: pickFieldsFromArray(data.body || [], ProjectAPI.eventFieldFields)
29
+ };
30
+ }
31
+ /**
32
+ * Create a Project in an Organization
33
+ * POST /organizations/{organization_id}/projects
34
+ * @param organizationId The organization ID
35
+ * @param data The project creation request body
36
+ * @returns A promise that resolves to the created project
37
+ */
38
+ async createProject(organizationId, data) {
39
+ const url = `/organizations/${organizationId}/projects`;
40
+ return await this.request({
41
+ method: 'POST',
42
+ url,
43
+ body: data,
44
+ });
27
45
  }
28
46
  }
@@ -31,12 +31,17 @@ export class BaseAPI {
31
31
  const url = options.url.startsWith('http') ? options.url : `${this.configuration.basePath || ''}${options.url}`;
32
32
  let results = [];
33
33
  let nextUrl = url;
34
+ let apiResponse;
34
35
  do {
35
36
  const response = await fetch(nextUrl, fetchOptions);
36
37
  if (!response.ok) {
37
38
  const errorText = await response.text();
38
39
  throw new Error(`Request failed with status ${response.status}: ${errorText}`);
39
40
  }
41
+ apiResponse = {
42
+ status: response.status,
43
+ headers: response.headers
44
+ };
40
45
  const data = await response.json();
41
46
  if (paginate) {
42
47
  results = results.concat(data);
@@ -50,9 +55,12 @@ export class BaseAPI {
50
55
  }
51
56
  }
52
57
  else {
53
- return data;
58
+ apiResponse.body = data;
54
59
  }
55
60
  } while (paginate && nextUrl);
56
- return results;
61
+ if (paginate) {
62
+ apiResponse.body = results;
63
+ }
64
+ return apiResponse;
57
65
  }
58
66
  }