@symbo.ls/sdk 2.34.4 → 2.34.7
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.
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/services/BranchService.js +4 -4
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +1 -1
- package/dist/cjs/services/PullRequestService.js +8 -6
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +13 -1
- package/dist/cjs/utils/services.js +26 -1
- package/dist/esm/index.js +751 -12
- package/dist/esm/services/BranchService.js +4 -4
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1 -1
- package/dist/esm/services/PullRequestService.js +8 -6
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +708 -12
- package/dist/esm/utils/services.js +26 -1
- package/dist/node/index.js +32 -2
- package/dist/node/services/BranchService.js +4 -4
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +1 -1
- package/dist/node/services/PullRequestService.js +8 -6
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +13 -1
- package/dist/node/utils/services.js +26 -1
- package/package.json +8 -7
- package/src/index.js +40 -13
- package/src/services/BranchService.js +5 -5
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +1 -1
- package/src/services/PullRequestService.js +6 -6
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +16 -2
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +0 -2
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/utils/services.js +29 -1
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import { BaseService } from './BaseService.js'
|
|
2
|
+
|
|
3
|
+
export class IntegrationService extends BaseService {
|
|
4
|
+
// ==================== INTEGRATION METHODS ====================
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Programmatic auth sanity check (API key based).
|
|
8
|
+
*
|
|
9
|
+
* Mirrors: GET /integrations/whoami (requireApiKey)
|
|
10
|
+
*
|
|
11
|
+
* Assumption: backend reads API key from `x-api-key` header.
|
|
12
|
+
* You can override via `options.headers`.
|
|
13
|
+
*/
|
|
14
|
+
async integrationWhoami (apiKey, options = {}) {
|
|
15
|
+
this._requireReady('integrationWhoami')
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
throw new Error('API key is required')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const headers = {
|
|
21
|
+
'x-api-key': apiKey,
|
|
22
|
+
...(options.headers || {})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const response = await this._request('/integrations/whoami', {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers,
|
|
29
|
+
methodName: 'integrationWhoami'
|
|
30
|
+
})
|
|
31
|
+
if (response.success) {
|
|
32
|
+
return response.data
|
|
33
|
+
}
|
|
34
|
+
throw new Error(response.message)
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(`Failed to validate integration API key: ${error.message}`, { cause: error })
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* List integrations visible to the user.
|
|
42
|
+
*
|
|
43
|
+
* Mirrors: GET /integrations?orgId=&projectId=
|
|
44
|
+
*/
|
|
45
|
+
async listIntegrations (options = {}) {
|
|
46
|
+
this._requireReady('listIntegrations')
|
|
47
|
+
|
|
48
|
+
const { orgId, projectId } = options || {}
|
|
49
|
+
const queryParams = new URLSearchParams()
|
|
50
|
+
if (orgId != null) { queryParams.append('orgId', String(orgId)) }
|
|
51
|
+
if (projectId != null) { queryParams.append('projectId', String(projectId)) }
|
|
52
|
+
|
|
53
|
+
const queryString = queryParams.toString()
|
|
54
|
+
const url = `/integrations${queryString ? `?${queryString}` : ''}`
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const response = await this._request(url, {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
methodName: 'listIntegrations'
|
|
60
|
+
})
|
|
61
|
+
if (response.success) {
|
|
62
|
+
return response.data
|
|
63
|
+
}
|
|
64
|
+
throw new Error(response.message)
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error(`Failed to list integrations: ${error.message}`, { cause: error })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create an integration.
|
|
72
|
+
*
|
|
73
|
+
* Mirrors: POST /integrations
|
|
74
|
+
*/
|
|
75
|
+
async createIntegration (data = {}) {
|
|
76
|
+
this._requireReady('createIntegration')
|
|
77
|
+
if (!data || typeof data !== 'object') {
|
|
78
|
+
throw new Error('Integration payload is required')
|
|
79
|
+
}
|
|
80
|
+
if (!data.name) {
|
|
81
|
+
throw new Error('Integration name is required')
|
|
82
|
+
}
|
|
83
|
+
if (!data.ownerType) {
|
|
84
|
+
throw new Error('ownerType is required')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const response = await this._request('/integrations', {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
body: JSON.stringify(data),
|
|
91
|
+
methodName: 'createIntegration'
|
|
92
|
+
})
|
|
93
|
+
if (response.success) {
|
|
94
|
+
return response.data
|
|
95
|
+
}
|
|
96
|
+
throw new Error(response.message)
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new Error(`Failed to create integration: ${error.message}`, { cause: error })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Update an integration.
|
|
104
|
+
*
|
|
105
|
+
* Mirrors: PATCH /integrations/:integrationId
|
|
106
|
+
*/
|
|
107
|
+
async updateIntegration (integrationId, update = {}) {
|
|
108
|
+
this._requireReady('updateIntegration')
|
|
109
|
+
if (!integrationId) {
|
|
110
|
+
throw new Error('Integration ID is required')
|
|
111
|
+
}
|
|
112
|
+
if (!update || typeof update !== 'object') {
|
|
113
|
+
throw new Error('Update payload is required')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const response = await this._request(`/integrations/${integrationId}`, {
|
|
118
|
+
method: 'PATCH',
|
|
119
|
+
body: JSON.stringify(update),
|
|
120
|
+
methodName: 'updateIntegration'
|
|
121
|
+
})
|
|
122
|
+
if (response.success) {
|
|
123
|
+
return response.data
|
|
124
|
+
}
|
|
125
|
+
throw new Error(response.message)
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw new Error(`Failed to update integration: ${error.message}`, { cause: error })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ==================== INTEGRATION API KEY METHODS ====================
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Create a new API key for an integration.
|
|
135
|
+
*
|
|
136
|
+
* Mirrors: POST /integrations/:integrationId/api-keys
|
|
137
|
+
*/
|
|
138
|
+
async createIntegrationApiKey (integrationId, data = {}) {
|
|
139
|
+
this._requireReady('createIntegrationApiKey')
|
|
140
|
+
if (!integrationId) {
|
|
141
|
+
throw new Error('Integration ID is required')
|
|
142
|
+
}
|
|
143
|
+
if (!data || typeof data !== 'object') {
|
|
144
|
+
throw new Error('API key payload is required')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const response = await this._request(`/integrations/${integrationId}/api-keys`, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
body: JSON.stringify(data),
|
|
151
|
+
methodName: 'createIntegrationApiKey'
|
|
152
|
+
})
|
|
153
|
+
if (response.success) {
|
|
154
|
+
return response.data
|
|
155
|
+
}
|
|
156
|
+
throw new Error(response.message)
|
|
157
|
+
} catch (error) {
|
|
158
|
+
throw new Error(`Failed to create integration API key: ${error.message}`, { cause: error })
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* List API keys for an integration.
|
|
164
|
+
*
|
|
165
|
+
* Mirrors: GET /integrations/:integrationId/api-keys
|
|
166
|
+
*/
|
|
167
|
+
async listIntegrationApiKeys (integrationId) {
|
|
168
|
+
this._requireReady('listIntegrationApiKeys')
|
|
169
|
+
if (!integrationId) {
|
|
170
|
+
throw new Error('Integration ID is required')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
const response = await this._request(`/integrations/${integrationId}/api-keys`, {
|
|
175
|
+
method: 'GET',
|
|
176
|
+
methodName: 'listIntegrationApiKeys'
|
|
177
|
+
})
|
|
178
|
+
if (response.success) {
|
|
179
|
+
return response.data
|
|
180
|
+
}
|
|
181
|
+
throw new Error(response.message)
|
|
182
|
+
} catch (error) {
|
|
183
|
+
throw new Error(`Failed to list integration API keys: ${error.message}`, { cause: error })
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Revoke an API key for an integration.
|
|
189
|
+
*
|
|
190
|
+
* Mirrors: POST /integrations/:integrationId/api-keys/:keyId/revoke
|
|
191
|
+
*/
|
|
192
|
+
async revokeIntegrationApiKey (integrationId, keyId) {
|
|
193
|
+
this._requireReady('revokeIntegrationApiKey')
|
|
194
|
+
if (!integrationId) {
|
|
195
|
+
throw new Error('Integration ID is required')
|
|
196
|
+
}
|
|
197
|
+
if (!keyId) {
|
|
198
|
+
throw new Error('API key ID is required')
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
const response = await this._request(
|
|
203
|
+
`/integrations/${integrationId}/api-keys/${keyId}/revoke`,
|
|
204
|
+
{
|
|
205
|
+
method: 'POST',
|
|
206
|
+
methodName: 'revokeIntegrationApiKey'
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
if (response.success) {
|
|
210
|
+
return response.data
|
|
211
|
+
}
|
|
212
|
+
throw new Error(response.message)
|
|
213
|
+
} catch (error) {
|
|
214
|
+
throw new Error(`Failed to revoke integration API key: ${error.message}`, { cause: error })
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ==================== WEBHOOK METHODS ====================
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Create a webhook endpoint for an integration.
|
|
222
|
+
*
|
|
223
|
+
* Mirrors: POST /integrations/:integrationId/webhooks
|
|
224
|
+
*/
|
|
225
|
+
async createIntegrationWebhook (integrationId, data = {}) {
|
|
226
|
+
this._requireReady('createIntegrationWebhook')
|
|
227
|
+
if (!integrationId) {
|
|
228
|
+
throw new Error('Integration ID is required')
|
|
229
|
+
}
|
|
230
|
+
if (!data || typeof data !== 'object') {
|
|
231
|
+
throw new Error('Webhook payload is required')
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const response = await this._request(`/integrations/${integrationId}/webhooks`, {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
body: JSON.stringify(data),
|
|
238
|
+
methodName: 'createIntegrationWebhook'
|
|
239
|
+
})
|
|
240
|
+
if (response.success) {
|
|
241
|
+
return response.data
|
|
242
|
+
}
|
|
243
|
+
throw new Error(response.message)
|
|
244
|
+
} catch (error) {
|
|
245
|
+
throw new Error(`Failed to create integration webhook: ${error.message}`, { cause: error })
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* List webhook endpoints for an integration.
|
|
251
|
+
*
|
|
252
|
+
* Mirrors: GET /integrations/:integrationId/webhooks
|
|
253
|
+
*/
|
|
254
|
+
async listIntegrationWebhooks (integrationId) {
|
|
255
|
+
this._requireReady('listIntegrationWebhooks')
|
|
256
|
+
if (!integrationId) {
|
|
257
|
+
throw new Error('Integration ID is required')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const response = await this._request(`/integrations/${integrationId}/webhooks`, {
|
|
262
|
+
method: 'GET',
|
|
263
|
+
methodName: 'listIntegrationWebhooks'
|
|
264
|
+
})
|
|
265
|
+
if (response.success) {
|
|
266
|
+
return response.data
|
|
267
|
+
}
|
|
268
|
+
throw new Error(response.message)
|
|
269
|
+
} catch (error) {
|
|
270
|
+
throw new Error(`Failed to list integration webhooks: ${error.message}`, { cause: error })
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Update a webhook endpoint for an integration.
|
|
276
|
+
*
|
|
277
|
+
* Mirrors: PATCH /integrations/:integrationId/webhooks/:webhookId
|
|
278
|
+
*/
|
|
279
|
+
async updateIntegrationWebhook (integrationId, webhookId, update = {}) {
|
|
280
|
+
this._requireReady('updateIntegrationWebhook')
|
|
281
|
+
if (!integrationId) {
|
|
282
|
+
throw new Error('Integration ID is required')
|
|
283
|
+
}
|
|
284
|
+
if (!webhookId) {
|
|
285
|
+
throw new Error('Webhook ID is required')
|
|
286
|
+
}
|
|
287
|
+
if (!update || typeof update !== 'object') {
|
|
288
|
+
throw new Error('Update payload is required')
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
try {
|
|
292
|
+
const response = await this._request(
|
|
293
|
+
`/integrations/${integrationId}/webhooks/${webhookId}`,
|
|
294
|
+
{
|
|
295
|
+
method: 'PATCH',
|
|
296
|
+
body: JSON.stringify(update),
|
|
297
|
+
methodName: 'updateIntegrationWebhook'
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
if (response.success) {
|
|
301
|
+
return response.data
|
|
302
|
+
}
|
|
303
|
+
throw new Error(response.message)
|
|
304
|
+
} catch (error) {
|
|
305
|
+
throw new Error(`Failed to update integration webhook: ${error.message}`, { cause: error })
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Delete a webhook endpoint for an integration.
|
|
311
|
+
*
|
|
312
|
+
* Mirrors: DELETE /integrations/:integrationId/webhooks/:webhookId
|
|
313
|
+
*/
|
|
314
|
+
async deleteIntegrationWebhook (integrationId, webhookId) {
|
|
315
|
+
this._requireReady('deleteIntegrationWebhook')
|
|
316
|
+
if (!integrationId) {
|
|
317
|
+
throw new Error('Integration ID is required')
|
|
318
|
+
}
|
|
319
|
+
if (!webhookId) {
|
|
320
|
+
throw new Error('Webhook ID is required')
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
const response = await this._request(
|
|
325
|
+
`/integrations/${integrationId}/webhooks/${webhookId}`,
|
|
326
|
+
{
|
|
327
|
+
method: 'DELETE',
|
|
328
|
+
methodName: 'deleteIntegrationWebhook'
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
if (response && response.success) {
|
|
332
|
+
return response.data
|
|
333
|
+
}
|
|
334
|
+
// Some endpoints may return 204; BaseService returns null then.
|
|
335
|
+
if (response == null) {
|
|
336
|
+
return null
|
|
337
|
+
}
|
|
338
|
+
throw new Error(response.message)
|
|
339
|
+
} catch (error) {
|
|
340
|
+
throw new Error(`Failed to delete integration webhook: ${error.message}`, { cause: error })
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* List webhook deliveries for an integration webhook.
|
|
346
|
+
*
|
|
347
|
+
* Mirrors: GET /integrations/:integrationId/webhooks/:webhookId/deliveries
|
|
348
|
+
*/
|
|
349
|
+
async listIntegrationWebhookDeliveries (integrationId, webhookId, options = {}) {
|
|
350
|
+
this._requireReady('listIntegrationWebhookDeliveries')
|
|
351
|
+
if (!integrationId) {
|
|
352
|
+
throw new Error('Integration ID is required')
|
|
353
|
+
}
|
|
354
|
+
if (!webhookId) {
|
|
355
|
+
throw new Error('Webhook ID is required')
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const { page, limit, status, includePayload } = options || {}
|
|
359
|
+
const queryParams = new URLSearchParams()
|
|
360
|
+
if (page != null) { queryParams.append('page', String(page)) }
|
|
361
|
+
if (limit != null) { queryParams.append('limit', String(limit)) }
|
|
362
|
+
if (status != null) { queryParams.append('status', String(status)) }
|
|
363
|
+
if (includePayload != null) { queryParams.append('includePayload', String(includePayload)) }
|
|
364
|
+
|
|
365
|
+
const queryString = queryParams.toString()
|
|
366
|
+
const url = `/integrations/${integrationId}/webhooks/${webhookId}/deliveries${queryString ? `?${queryString}` : ''}`
|
|
367
|
+
|
|
368
|
+
try {
|
|
369
|
+
const response = await this._request(url, {
|
|
370
|
+
method: 'GET',
|
|
371
|
+
methodName: 'listIntegrationWebhookDeliveries'
|
|
372
|
+
})
|
|
373
|
+
if (response.success) {
|
|
374
|
+
return response.data
|
|
375
|
+
}
|
|
376
|
+
throw new Error(response.message)
|
|
377
|
+
} catch (error) {
|
|
378
|
+
throw new Error(`Failed to list webhook deliveries: ${error.message}`, { cause: error })
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Replay a webhook delivery.
|
|
384
|
+
*
|
|
385
|
+
* Mirrors: POST /integrations/:integrationId/webhooks/:webhookId/replay
|
|
386
|
+
* Body: { deliveryId }
|
|
387
|
+
*/
|
|
388
|
+
async replayIntegrationWebhookDelivery (integrationId, webhookId, deliveryId) {
|
|
389
|
+
this._requireReady('replayIntegrationWebhookDelivery')
|
|
390
|
+
if (!integrationId) {
|
|
391
|
+
throw new Error('Integration ID is required')
|
|
392
|
+
}
|
|
393
|
+
if (!webhookId) {
|
|
394
|
+
throw new Error('Webhook ID is required')
|
|
395
|
+
}
|
|
396
|
+
if (!deliveryId) {
|
|
397
|
+
throw new Error('deliveryId is required')
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
try {
|
|
401
|
+
const response = await this._request(
|
|
402
|
+
`/integrations/${integrationId}/webhooks/${webhookId}/replay`,
|
|
403
|
+
{
|
|
404
|
+
method: 'POST',
|
|
405
|
+
body: JSON.stringify({ deliveryId }),
|
|
406
|
+
methodName: 'replayIntegrationWebhookDelivery'
|
|
407
|
+
}
|
|
408
|
+
)
|
|
409
|
+
if (response.success) {
|
|
410
|
+
return response.data
|
|
411
|
+
}
|
|
412
|
+
throw new Error(response.message)
|
|
413
|
+
} catch (error) {
|
|
414
|
+
throw new Error(`Failed to replay webhook delivery: ${error.message}`, { cause: error })
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// ==================== CONNECTOR METHODS (GITHUB) ====================
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* List GitHub connectors for an integration.
|
|
422
|
+
*
|
|
423
|
+
* Mirrors: GET /integrations/:integrationId/connectors/github
|
|
424
|
+
*/
|
|
425
|
+
async listGitHubConnectors (integrationId) {
|
|
426
|
+
this._requireReady('listGitHubConnectors')
|
|
427
|
+
if (!integrationId) {
|
|
428
|
+
throw new Error('Integration ID is required')
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
try {
|
|
432
|
+
const response = await this._request(`/integrations/${integrationId}/connectors/github`, {
|
|
433
|
+
method: 'GET',
|
|
434
|
+
methodName: 'listGitHubConnectors'
|
|
435
|
+
})
|
|
436
|
+
if (response.success) {
|
|
437
|
+
return response.data
|
|
438
|
+
}
|
|
439
|
+
throw new Error(response.message)
|
|
440
|
+
} catch (error) {
|
|
441
|
+
throw new Error(`Failed to list GitHub connectors: ${error.message}`, { cause: error })
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Create a GitHub connector for an integration.
|
|
447
|
+
*
|
|
448
|
+
* Mirrors: POST /integrations/:integrationId/connectors/github
|
|
449
|
+
*/
|
|
450
|
+
async createGitHubConnector (integrationId, data = {}) {
|
|
451
|
+
this._requireReady('createGitHubConnector')
|
|
452
|
+
if (!integrationId) {
|
|
453
|
+
throw new Error('Integration ID is required')
|
|
454
|
+
}
|
|
455
|
+
if (!data || typeof data !== 'object') {
|
|
456
|
+
throw new Error('Connector payload is required')
|
|
457
|
+
}
|
|
458
|
+
if (!data.projectId) {
|
|
459
|
+
throw new Error('projectId is required')
|
|
460
|
+
}
|
|
461
|
+
if (!data.repository) {
|
|
462
|
+
throw new Error('repository is required')
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
const response = await this._request(`/integrations/${integrationId}/connectors/github`, {
|
|
467
|
+
method: 'POST',
|
|
468
|
+
body: JSON.stringify(data),
|
|
469
|
+
methodName: 'createGitHubConnector'
|
|
470
|
+
})
|
|
471
|
+
if (response.success) {
|
|
472
|
+
return response.data
|
|
473
|
+
}
|
|
474
|
+
throw new Error(response.message)
|
|
475
|
+
} catch (error) {
|
|
476
|
+
throw new Error(`Failed to create GitHub connector: ${error.message}`, { cause: error })
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Update a GitHub connector.
|
|
482
|
+
*
|
|
483
|
+
* Mirrors: PATCH /integrations/:integrationId/connectors/github/:connectorId
|
|
484
|
+
*/
|
|
485
|
+
async updateGitHubConnector (integrationId, connectorId, update = {}) {
|
|
486
|
+
this._requireReady('updateGitHubConnector')
|
|
487
|
+
if (!integrationId) {
|
|
488
|
+
throw new Error('Integration ID is required')
|
|
489
|
+
}
|
|
490
|
+
if (!connectorId) {
|
|
491
|
+
throw new Error('Connector ID is required')
|
|
492
|
+
}
|
|
493
|
+
if (!update || typeof update !== 'object') {
|
|
494
|
+
throw new Error('Update payload is required')
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
try {
|
|
498
|
+
const response = await this._request(
|
|
499
|
+
`/integrations/${integrationId}/connectors/github/${connectorId}`,
|
|
500
|
+
{
|
|
501
|
+
method: 'PATCH',
|
|
502
|
+
body: JSON.stringify(update),
|
|
503
|
+
methodName: 'updateGitHubConnector'
|
|
504
|
+
}
|
|
505
|
+
)
|
|
506
|
+
if (response.success) {
|
|
507
|
+
return response.data
|
|
508
|
+
}
|
|
509
|
+
throw new Error(response.message)
|
|
510
|
+
} catch (error) {
|
|
511
|
+
throw new Error(`Failed to update GitHub connector: ${error.message}`, { cause: error })
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Delete a GitHub connector.
|
|
517
|
+
*
|
|
518
|
+
* Mirrors: DELETE /integrations/:integrationId/connectors/github/:connectorId
|
|
519
|
+
*/
|
|
520
|
+
async deleteGitHubConnector (integrationId, connectorId) {
|
|
521
|
+
this._requireReady('deleteGitHubConnector')
|
|
522
|
+
if (!integrationId) {
|
|
523
|
+
throw new Error('Integration ID is required')
|
|
524
|
+
}
|
|
525
|
+
if (!connectorId) {
|
|
526
|
+
throw new Error('Connector ID is required')
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
const response = await this._request(
|
|
531
|
+
`/integrations/${integrationId}/connectors/github/${connectorId}`,
|
|
532
|
+
{
|
|
533
|
+
method: 'DELETE',
|
|
534
|
+
methodName: 'deleteGitHubConnector'
|
|
535
|
+
}
|
|
536
|
+
)
|
|
537
|
+
if (response && response.success) {
|
|
538
|
+
return response.data
|
|
539
|
+
}
|
|
540
|
+
if (response == null) {
|
|
541
|
+
return null
|
|
542
|
+
}
|
|
543
|
+
throw new Error(response.message)
|
|
544
|
+
} catch (error) {
|
|
545
|
+
throw new Error(`Failed to delete GitHub connector: ${error.message}`, { cause: error })
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaseService } from './BaseService.js'
|
|
2
|
+
|
|
3
|
+
export class MetricsService extends BaseService {
|
|
4
|
+
// ==================== METRICS METHODS ====================
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Contribution heat-map stats.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors: GET /metrics/contributions (MetricsController.getContributions)
|
|
10
|
+
*/
|
|
11
|
+
async getContributions (options = {}) {
|
|
12
|
+
this._requireReady('getContributions')
|
|
13
|
+
|
|
14
|
+
const { projectId, userId, from, to } = options || {}
|
|
15
|
+
const queryParams = new URLSearchParams()
|
|
16
|
+
|
|
17
|
+
if (projectId != null) { queryParams.append('projectId', String(projectId)) }
|
|
18
|
+
if (userId != null) { queryParams.append('userId', String(userId)) }
|
|
19
|
+
if (from != null) { queryParams.append('from', String(from)) }
|
|
20
|
+
if (to != null) { queryParams.append('to', String(to)) }
|
|
21
|
+
|
|
22
|
+
const queryString = queryParams.toString()
|
|
23
|
+
const url = `/metrics/contributions${queryString ? `?${queryString}` : ''}`
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const response = await this._request(url, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
methodName: 'getContributions'
|
|
29
|
+
})
|
|
30
|
+
if (response.success) {
|
|
31
|
+
return response.data
|
|
32
|
+
}
|
|
33
|
+
throw new Error(response.message)
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error(`Failed to get contribution stats: ${error.message}`, { cause: error })
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// End
|
|
@@ -149,7 +149,7 @@ export class PaymentService extends BaseService {
|
|
|
149
149
|
status: status.status
|
|
150
150
|
}
|
|
151
151
|
} catch (error) {
|
|
152
|
-
throw new Error(`Failed to get subscription details: ${error.message}
|
|
152
|
+
throw new Error(`Failed to get subscription details: ${error.message}`, { cause: error })
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -208,7 +208,7 @@ export class PullRequestService extends BaseService {
|
|
|
208
208
|
error.message.includes('conflicts') ||
|
|
209
209
|
error.message.includes('409')
|
|
210
210
|
) {
|
|
211
|
-
throw new Error(`Pull request has merge conflicts: ${error.message}
|
|
211
|
+
throw new Error(`Pull request has merge conflicts: ${error.message}`, { cause: error })
|
|
212
212
|
}
|
|
213
213
|
throw new Error(`Failed to merge pull request: ${error.message}`, { cause: error })
|
|
214
214
|
}
|
|
@@ -343,7 +343,7 @@ export class PullRequestService extends BaseService {
|
|
|
343
343
|
return prData?.data?.canMerge || false
|
|
344
344
|
} catch (error) {
|
|
345
345
|
throw new Error(
|
|
346
|
-
`Failed to check pull request mergeability: ${error.message}
|
|
346
|
+
`Failed to check pull request mergeability: ${error.message}`, { cause: error }
|
|
347
347
|
)
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -373,7 +373,7 @@ export class PullRequestService extends BaseService {
|
|
|
373
373
|
}
|
|
374
374
|
} catch (error) {
|
|
375
375
|
throw new Error(
|
|
376
|
-
`Failed to get pull request status summary: ${error.message}
|
|
376
|
+
`Failed to get pull request status summary: ${error.message}`, { cause: error }
|
|
377
377
|
)
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -473,7 +473,7 @@ export class PullRequestService extends BaseService {
|
|
|
473
473
|
|
|
474
474
|
return stats
|
|
475
475
|
} catch (error) {
|
|
476
|
-
throw new Error(`Failed to get pull request stats: ${error.message}
|
|
476
|
+
throw new Error(`Failed to get pull request stats: ${error.message}`, { cause: error })
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
|
|
@@ -502,7 +502,7 @@ export class PullRequestService extends BaseService {
|
|
|
502
502
|
}
|
|
503
503
|
throw new Error(response.message)
|
|
504
504
|
} catch (error) {
|
|
505
|
-
throw new Error(`Failed to close pull request: ${error.message}
|
|
505
|
+
throw new Error(`Failed to close pull request: ${error.message}`, { cause: error })
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
|
|
@@ -531,7 +531,7 @@ export class PullRequestService extends BaseService {
|
|
|
531
531
|
}
|
|
532
532
|
throw new Error(response.message)
|
|
533
533
|
} catch (error) {
|
|
534
|
-
throw new Error(`Failed to reopen pull request: ${error.message}
|
|
534
|
+
throw new Error(`Failed to reopen pull request: ${error.message}`, { cause: error })
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
537
|
}
|