@symbo.ls/sdk 3.1.2 → 3.2.6

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 (187) hide show
  1. package/README.md +143 -2
  2. package/dist/cjs/config/environment.js +98 -30
  3. package/dist/cjs/index.js +144 -24
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +743 -0
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +64 -16
  23. package/dist/cjs/state/RootStateManager.js +65 -0
  24. package/dist/cjs/state/rootEventBus.js +74 -0
  25. package/dist/cjs/utils/CollabClient.js +223 -0
  26. package/dist/cjs/utils/TokenManager.js +78 -30
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +145 -0
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +301 -103
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +98 -30
  33. package/dist/esm/index.js +49505 -8718
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +26895 -0
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +49062 -8569
  53. package/dist/esm/state/RootStateManager.js +90 -0
  54. package/dist/esm/state/rootEventBus.js +56 -0
  55. package/dist/esm/utils/CollabClient.js +18889 -0
  56. package/dist/esm/utils/TokenManager.js +78 -30
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +7011 -0
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +301 -103
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +98 -30
  63. package/dist/node/index.js +175 -32
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +724 -0
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +64 -16
  83. package/dist/node/state/RootStateManager.js +36 -0
  84. package/dist/node/state/rootEventBus.js +55 -0
  85. package/dist/node/utils/CollabClient.js +194 -0
  86. package/dist/node/utils/TokenManager.js +78 -30
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +116 -0
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +301 -103
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +39 -21
  93. package/src/config/environment.js +99 -28
  94. package/src/index.js +181 -36
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +900 -0
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +80 -13
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +76 -0
  148. package/src/state/rootEventBus.js +67 -0
  149. package/src/utils/CollabClient.js +248 -0
  150. package/src/utils/TokenManager.js +88 -33
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +144 -0
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +326 -107
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -1751
  159. package/dist/cjs/services/SocketIOService.js +0 -307
  160. package/dist/cjs/services/SocketService.js +0 -161
  161. package/dist/cjs/services/SymstoryService.js +0 -571
  162. package/dist/cjs/utils/basedQuerys.js +0 -181
  163. package/dist/cjs/utils/symstoryClient.js +0 -259
  164. package/dist/esm/services/AIService.js +0 -185
  165. package/dist/esm/services/BasedService.js +0 -5278
  166. package/dist/esm/services/CoreService.js +0 -2264
  167. package/dist/esm/services/SocketIOService.js +0 -470
  168. package/dist/esm/services/SocketService.js +0 -191
  169. package/dist/esm/services/SymstoryService.js +0 -7041
  170. package/dist/esm/utils/basedQuerys.js +0 -163
  171. package/dist/esm/utils/symstoryClient.js +0 -370
  172. package/dist/node/services/AIService.js +0 -136
  173. package/dist/node/services/BasedService.js +0 -1156
  174. package/dist/node/services/CoreService.js +0 -1722
  175. package/dist/node/services/SocketIOService.js +0 -278
  176. package/dist/node/services/SocketService.js +0 -142
  177. package/dist/node/services/SymstoryService.js +0 -542
  178. package/dist/node/utils/basedQuerys.js +0 -162
  179. package/dist/node/utils/symstoryClient.js +0 -230
  180. package/src/services/AIService.js +0 -150
  181. package/src/services/BasedService.js +0 -1301
  182. package/src/services/CoreService.js +0 -1943
  183. package/src/services/SocketIOService.js +0 -334
  184. package/src/services/SocketService.js +0 -168
  185. package/src/services/SymstoryService.js +0 -649
  186. package/src/utils/basedQuerys.js +0 -164
  187. package/src/utils/symstoryClient.js +0 -252
@@ -0,0 +1,503 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var PullRequestService_exports = {};
19
+ __export(PullRequestService_exports, {
20
+ PullRequestService: () => PullRequestService
21
+ });
22
+ module.exports = __toCommonJS(PullRequestService_exports);
23
+ var import_BaseService = require("./BaseService.js");
24
+ class PullRequestService extends import_BaseService.BaseService {
25
+ // ==================== PULL REQUEST METHODS ====================
26
+ /**
27
+ * Create a new pull request
28
+ */
29
+ async createPullRequest(projectId, pullRequestData) {
30
+ this._requireReady("createPullRequest");
31
+ if (!projectId) {
32
+ throw new Error("Project ID is required");
33
+ }
34
+ if (!pullRequestData.source || !pullRequestData.target || !pullRequestData.title) {
35
+ throw new Error("Source branch, target branch, and title are required");
36
+ }
37
+ try {
38
+ const response = await this._request(
39
+ `/projects/${projectId}/pull-requests`,
40
+ {
41
+ method: "POST",
42
+ body: JSON.stringify(pullRequestData),
43
+ methodName: "createPullRequest"
44
+ }
45
+ );
46
+ if (response.success) {
47
+ return response.data;
48
+ }
49
+ throw new Error(response.message);
50
+ } catch (error) {
51
+ throw new Error(`Failed to create pull request: ${error.message}`, { cause: error });
52
+ }
53
+ }
54
+ /**
55
+ * List pull requests for a project with filtering options
56
+ */
57
+ async listPullRequests(projectId, options = {}) {
58
+ this._requireReady("listPullRequests");
59
+ if (!projectId) {
60
+ throw new Error("Project ID is required");
61
+ }
62
+ const { status = "open", source, target, page = 1, limit = 20 } = options;
63
+ const queryParams = new URLSearchParams({
64
+ status,
65
+ page: page.toString(),
66
+ limit: limit.toString()
67
+ });
68
+ if (source) {
69
+ queryParams.append("source", source);
70
+ }
71
+ if (target) {
72
+ queryParams.append("target", target);
73
+ }
74
+ try {
75
+ const response = await this._request(
76
+ `/projects/${projectId}/pull-requests?${queryParams.toString()}`,
77
+ {
78
+ method: "GET",
79
+ methodName: "listPullRequests"
80
+ }
81
+ );
82
+ if (response.success) {
83
+ return response.data;
84
+ }
85
+ throw new Error(response.message);
86
+ } catch (error) {
87
+ throw new Error(`Failed to list pull requests: ${error.message}`, { cause: error });
88
+ }
89
+ }
90
+ /**
91
+ * Get detailed information about a specific pull request
92
+ */
93
+ async getPullRequest(projectId, prId) {
94
+ this._requireReady("getPullRequest");
95
+ if (!projectId) {
96
+ throw new Error("Project ID is required");
97
+ }
98
+ if (!prId) {
99
+ throw new Error("Pull request ID is required");
100
+ }
101
+ try {
102
+ const response = await this._request(
103
+ `/projects/${projectId}/pull-requests/${prId}`,
104
+ {
105
+ method: "GET",
106
+ methodName: "getPullRequest"
107
+ }
108
+ );
109
+ if (response.success) {
110
+ return response.data;
111
+ }
112
+ throw new Error(response.message);
113
+ } catch (error) {
114
+ throw new Error(`Failed to get pull request: ${error.message}`, { cause: error });
115
+ }
116
+ }
117
+ /**
118
+ * Submit a review for a pull request
119
+ */
120
+ async reviewPullRequest(projectId, prId, reviewData) {
121
+ this._requireReady("reviewPullRequest");
122
+ if (!projectId) {
123
+ throw new Error("Project ID is required");
124
+ }
125
+ if (!prId) {
126
+ throw new Error("Pull request ID is required");
127
+ }
128
+ const validStatuses = ["approved", "requested_changes", "feedback"];
129
+ if (reviewData.status && !validStatuses.includes(reviewData.status)) {
130
+ throw new Error(
131
+ `Invalid review status. Must be one of: ${validStatuses.join(", ")}`
132
+ );
133
+ }
134
+ try {
135
+ const response = await this._request(
136
+ `/projects/${projectId}/pull-requests/${prId}/review`,
137
+ {
138
+ method: "POST",
139
+ body: JSON.stringify(reviewData),
140
+ methodName: "reviewPullRequest"
141
+ }
142
+ );
143
+ if (response.success) {
144
+ return response;
145
+ }
146
+ throw new Error(response.message);
147
+ } catch (error) {
148
+ throw new Error(`Failed to review pull request: ${error.message}`, { cause: error });
149
+ }
150
+ }
151
+ /**
152
+ * Add a comment to an existing review thread
153
+ */
154
+ async addPullRequestComment(projectId, prId, commentData) {
155
+ this._requireReady("addPullRequestComment");
156
+ if (!projectId) {
157
+ throw new Error("Project ID is required");
158
+ }
159
+ if (!prId) {
160
+ throw new Error("Pull request ID is required");
161
+ }
162
+ if (!commentData.value) {
163
+ throw new Error("Comment value is required");
164
+ }
165
+ try {
166
+ const response = await this._request(
167
+ `/projects/${projectId}/pull-requests/${prId}/comment`,
168
+ {
169
+ method: "POST",
170
+ body: JSON.stringify(commentData),
171
+ methodName: "addPullRequestComment"
172
+ }
173
+ );
174
+ if (response.success) {
175
+ return response;
176
+ }
177
+ throw new Error(response.message);
178
+ } catch (error) {
179
+ throw new Error(`Failed to add pull request comment: ${error.message}`, { cause: error });
180
+ }
181
+ }
182
+ /**
183
+ * Merge an approved pull request
184
+ */
185
+ async mergePullRequest(projectId, prId) {
186
+ this._requireReady("mergePullRequest");
187
+ if (!projectId) {
188
+ throw new Error("Project ID is required");
189
+ }
190
+ if (!prId) {
191
+ throw new Error("Pull request ID is required");
192
+ }
193
+ try {
194
+ const response = await this._request(
195
+ `/projects/${projectId}/pull-requests/${prId}/merge`,
196
+ {
197
+ method: "POST",
198
+ methodName: "mergePullRequest"
199
+ }
200
+ );
201
+ if (response.success) {
202
+ return response;
203
+ }
204
+ throw new Error(response.message);
205
+ } catch (error) {
206
+ if (error.message.includes("conflicts") || error.message.includes("409")) {
207
+ throw new Error(`Pull request has merge conflicts: ${error.message}`, { cause: error });
208
+ }
209
+ throw new Error(`Failed to merge pull request: ${error.message}`, { cause: error });
210
+ }
211
+ }
212
+ /**
213
+ * Get the diff/changes for a pull request
214
+ */
215
+ async getPullRequestDiff(projectId, prId) {
216
+ this._requireReady("getPullRequestDiff");
217
+ if (!projectId) {
218
+ throw new Error("Project ID is required");
219
+ }
220
+ if (!prId) {
221
+ throw new Error("Pull request ID is required");
222
+ }
223
+ try {
224
+ const response = await this._request(
225
+ `/projects/${projectId}/pull-requests/${prId}/diff`,
226
+ {
227
+ method: "GET",
228
+ methodName: "getPullRequestDiff"
229
+ }
230
+ );
231
+ if (response.success) {
232
+ return response.data;
233
+ }
234
+ throw new Error(response.message);
235
+ } catch (error) {
236
+ throw new Error(`Failed to get pull request diff: ${error.message}`, { cause: error });
237
+ }
238
+ }
239
+ // ==================== PULL REQUEST HELPER METHODS ====================
240
+ /**
241
+ * Helper method to create a pull request with validation
242
+ */
243
+ async createPullRequestWithValidation(projectId, data) {
244
+ const { source, target, title, description, changes } = data;
245
+ if (source === target) {
246
+ throw new Error("Source and target branches cannot be the same");
247
+ }
248
+ if (!title || title.trim().length === 0) {
249
+ throw new Error("Pull request title cannot be empty");
250
+ }
251
+ if (title.length > 200) {
252
+ throw new Error("Pull request title cannot exceed 200 characters");
253
+ }
254
+ const pullRequestData = {
255
+ source: source.trim(),
256
+ target: target.trim(),
257
+ title: title.trim(),
258
+ ...description && { description: description.trim() },
259
+ ...changes && { changes }
260
+ };
261
+ return await this.createPullRequest(projectId, pullRequestData);
262
+ }
263
+ /**
264
+ * Helper method to approve a pull request
265
+ */
266
+ async approvePullRequest(projectId, prId, comment = "") {
267
+ const reviewData = {
268
+ status: "approved",
269
+ ...comment && {
270
+ threads: [
271
+ {
272
+ comment,
273
+ type: "praise"
274
+ }
275
+ ]
276
+ }
277
+ };
278
+ return await this.reviewPullRequest(projectId, prId, reviewData);
279
+ }
280
+ /**
281
+ * Helper method to request changes on a pull request
282
+ */
283
+ async requestPullRequestChanges(projectId, prId, threads = []) {
284
+ if (!threads || threads.length === 0) {
285
+ throw new Error("Must provide specific feedback when requesting changes");
286
+ }
287
+ const reviewData = {
288
+ status: "requested_changes",
289
+ threads
290
+ };
291
+ return await this.reviewPullRequest(projectId, prId, reviewData);
292
+ }
293
+ /**
294
+ * Helper method to get pull requests by status
295
+ */
296
+ async getOpenPullRequests(projectId, options = {}) {
297
+ return await this.listPullRequests(projectId, {
298
+ ...options,
299
+ status: "open"
300
+ });
301
+ }
302
+ async getClosedPullRequests(projectId, options = {}) {
303
+ return await this.listPullRequests(projectId, {
304
+ ...options,
305
+ status: "closed"
306
+ });
307
+ }
308
+ async getMergedPullRequests(projectId, options = {}) {
309
+ return await this.listPullRequests(projectId, {
310
+ ...options,
311
+ status: "merged"
312
+ });
313
+ }
314
+ /**
315
+ * Helper method to check if a pull request is canMerge
316
+ */
317
+ async isPullRequestMergeable(projectId, prId) {
318
+ var _a;
319
+ try {
320
+ const prData = await this.getPullRequest(projectId, prId);
321
+ return ((_a = prData == null ? void 0 : prData.data) == null ? void 0 : _a.canMerge) || false;
322
+ } catch (error) {
323
+ throw new Error(
324
+ `Failed to check pull request mergeability: ${error.message}`,
325
+ { cause: error }
326
+ );
327
+ }
328
+ }
329
+ /**
330
+ * Helper method to get pull request status summary
331
+ */
332
+ async getPullRequestStatusSummary(projectId, prId) {
333
+ var _a, _b, _c;
334
+ try {
335
+ const prData = await this.getPullRequest(projectId, prId);
336
+ const pr = prData == null ? void 0 : prData.data;
337
+ if (!pr) {
338
+ throw new Error("Pull request not found");
339
+ }
340
+ return {
341
+ status: pr.status,
342
+ reviewStatus: pr.reviewStatus,
343
+ canMerge: pr.canMerge,
344
+ hasConflicts: !pr.canMerge,
345
+ reviewCount: ((_a = pr.reviews) == null ? void 0 : _a.length) || 0,
346
+ approvedReviews: ((_b = pr.reviews) == null ? void 0 : _b.filter((r) => r.status === "approved").length) || 0,
347
+ changesRequested: ((_c = pr.reviews) == null ? void 0 : _c.filter((r) => r.status === "requested_changes").length) || 0
348
+ };
349
+ } catch (error) {
350
+ throw new Error(
351
+ `Failed to get pull request status summary: ${error.message}`,
352
+ { cause: error }
353
+ );
354
+ }
355
+ }
356
+ /**
357
+ * Helper method to validate pull request data
358
+ */
359
+ validatePullRequestData(data) {
360
+ const errors = [];
361
+ if (!data.source || typeof data.source !== "string") {
362
+ errors.push("Source branch is required and must be a string");
363
+ }
364
+ if (!data.target || typeof data.target !== "string") {
365
+ errors.push("Target branch is required and must be a string");
366
+ }
367
+ if (data.source === data.target) {
368
+ errors.push("Source and target branches cannot be the same");
369
+ }
370
+ if (!data.title || typeof data.title !== "string") {
371
+ errors.push("Title is required and must be a string");
372
+ } else if (data.title.trim().length === 0) {
373
+ errors.push("Title cannot be empty");
374
+ } else if (data.title.length > 200) {
375
+ errors.push("Title cannot exceed 200 characters");
376
+ }
377
+ if (data.description && typeof data.description !== "string") {
378
+ errors.push("Description must be a string");
379
+ }
380
+ return {
381
+ isValid: errors.length === 0,
382
+ errors
383
+ };
384
+ }
385
+ /**
386
+ * Helper method to validate review data
387
+ */
388
+ validateReviewData(reviewData) {
389
+ const errors = [];
390
+ const validStatuses = ["approved", "requested_changes", "feedback"];
391
+ if (reviewData.status && !validStatuses.includes(reviewData.status)) {
392
+ errors.push(`Invalid review status. Must be one of: ${validStatuses.join(", ")}`);
393
+ }
394
+ if (reviewData.threads && !Array.isArray(reviewData.threads)) {
395
+ errors.push("Threads must be an array");
396
+ }
397
+ if (reviewData.threads) {
398
+ reviewData.threads.forEach((thread, index) => {
399
+ if (!thread.comment || typeof thread.comment !== "string") {
400
+ errors.push(`Thread ${index + 1}: Comment is required and must be a string`);
401
+ }
402
+ if (thread.type && !["praise", "issue", "suggestion"].includes(thread.type)) {
403
+ errors.push(`Thread ${index + 1}: Invalid thread type`);
404
+ }
405
+ });
406
+ }
407
+ return {
408
+ isValid: errors.length === 0,
409
+ errors
410
+ };
411
+ }
412
+ /**
413
+ * Helper method to get pull request statistics
414
+ */
415
+ async getPullRequestStats(projectId, options = {}) {
416
+ try {
417
+ const { status = "open" } = options;
418
+ const pullRequests = await this.listPullRequests(projectId, { status });
419
+ const stats = {
420
+ total: pullRequests.length,
421
+ open: 0,
422
+ closed: 0,
423
+ merged: 0,
424
+ withConflicts: 0,
425
+ readyToMerge: 0
426
+ };
427
+ pullRequests.forEach((pr) => {
428
+ if (pr.status === "open") {
429
+ stats.open++;
430
+ }
431
+ if (pr.status === "closed") {
432
+ stats.closed++;
433
+ }
434
+ if (pr.status === "merged") {
435
+ stats.merged++;
436
+ }
437
+ if (pr.hasConflicts) {
438
+ stats.withConflicts++;
439
+ }
440
+ if (pr.canMerge) {
441
+ stats.readyToMerge++;
442
+ }
443
+ });
444
+ return stats;
445
+ } catch (error) {
446
+ throw new Error(`Failed to get pull request stats: ${error.message}`, { cause: error });
447
+ }
448
+ }
449
+ /**
450
+ * Helper method to close a pull request
451
+ */
452
+ async closePullRequest(projectId, prId) {
453
+ this._requireReady("closePullRequest");
454
+ if (!projectId) {
455
+ throw new Error("Project ID is required");
456
+ }
457
+ if (!prId) {
458
+ throw new Error("Pull request ID is required");
459
+ }
460
+ try {
461
+ const response = await this._request(
462
+ `/projects/${projectId}/pull-requests/${prId}/close`,
463
+ {
464
+ method: "POST",
465
+ methodName: "closePullRequest"
466
+ }
467
+ );
468
+ if (response.success) {
469
+ return response.data;
470
+ }
471
+ throw new Error(response.message);
472
+ } catch (error) {
473
+ throw new Error(`Failed to close pull request: ${error.message}`, { cause: error });
474
+ }
475
+ }
476
+ /**
477
+ * Helper method to reopen a closed pull request
478
+ */
479
+ async reopenPullRequest(projectId, prId) {
480
+ this._requireReady("reopenPullRequest");
481
+ if (!projectId) {
482
+ throw new Error("Project ID is required");
483
+ }
484
+ if (!prId) {
485
+ throw new Error("Pull request ID is required");
486
+ }
487
+ try {
488
+ const response = await this._request(
489
+ `/projects/${projectId}/pull-requests/${prId}/reopen`,
490
+ {
491
+ method: "POST",
492
+ methodName: "reopenPullRequest"
493
+ }
494
+ );
495
+ if (response.success) {
496
+ return response.data;
497
+ }
498
+ throw new Error(response.message);
499
+ } catch (error) {
500
+ throw new Error(`Failed to reopen pull request: ${error.message}`, { cause: error });
501
+ }
502
+ }
503
+ }