@bundleup/sdk 0.0.17 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +1083 -2
- package/dist/index.d.mts +226 -139
- package/dist/index.d.ts +226 -139
- package/dist/index.js +363 -333
- package/dist/index.mjs +363 -333
- package/package.json +31 -11
- package/dist/chunk-B6T6V2FR.mjs +0 -24
- package/dist/chunk-GKEHPYLJ.mjs +0 -17
- package/dist/chunk-U6VVRHFA.mjs +0 -17
- package/dist/client.d.mts +0 -8
- package/dist/client.d.ts +0 -8
- package/dist/client.js +0 -119
- package/dist/client.mjs +0 -84
- package/dist/server.d.mts +0 -21
- package/dist/server.d.ts +0 -21
- package/dist/server.js +0 -94
- package/dist/server.mjs +0 -61
- package/dist/utils.d.mts +0 -5
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -50
- package/dist/utils.mjs +0 -10
package/dist/index.mjs
CHANGED
|
@@ -2,182 +2,18 @@
|
|
|
2
2
|
function isObject(value) {
|
|
3
3
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
constructor(apiKey) {
|
|
9
|
-
this.apiKey = apiKey;
|
|
10
|
-
this.baseUrl = "https://api.bundleup.io";
|
|
11
|
-
this.version = "v1";
|
|
12
|
-
}
|
|
13
|
-
buildUrl(path, searchParams = {}) {
|
|
14
|
-
if (!isObject(searchParams)) {
|
|
15
|
-
throw new Error("URL search params must be an object.");
|
|
16
|
-
}
|
|
17
|
-
const parts = [this.version, this.namespace, path].filter(Boolean).join("/");
|
|
18
|
-
searchParams = Object.entries(searchParams).reduce(
|
|
19
|
-
(acc, [key, value]) => {
|
|
20
|
-
if (value !== void 0 && value !== null) {
|
|
21
|
-
acc[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
},
|
|
25
|
-
{}
|
|
26
|
-
);
|
|
27
|
-
const url = new URL(parts, this.baseUrl);
|
|
28
|
-
url.search = new URLSearchParams(searchParams).toString();
|
|
29
|
-
return url;
|
|
30
|
-
}
|
|
31
|
-
get headers() {
|
|
32
|
-
return {
|
|
33
|
-
"Content-Type": "application/json",
|
|
34
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* List resources with optional query parameters.
|
|
39
|
-
* @param searchParams - Query parameters for filtering the list.
|
|
40
|
-
* @returns A promise that resolves to an array of resources.
|
|
41
|
-
* @throws If params is not an object or if the fetch request fails.
|
|
42
|
-
*/
|
|
43
|
-
async list(searchParams = {}) {
|
|
44
|
-
if (!isObject(searchParams)) {
|
|
45
|
-
throw new Error("List parameters must be an object.");
|
|
46
|
-
}
|
|
47
|
-
const url = this.buildUrl(null, searchParams);
|
|
48
|
-
const response = await fetch(url, {
|
|
49
|
-
method: "GET",
|
|
50
|
-
headers: this.headers
|
|
51
|
-
});
|
|
52
|
-
if (!response.ok) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
const data = await response.json();
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Create a new resource.
|
|
62
|
-
* @param body - The request body containing resource details.
|
|
63
|
-
* @returns A promise that resolves to the created resource.
|
|
64
|
-
* @throws If body is not an object or if the fetch request fails.
|
|
65
|
-
*/
|
|
66
|
-
async create(body) {
|
|
67
|
-
if (!isObject(body)) {
|
|
68
|
-
throw new Error("Request body must be an object.");
|
|
69
|
-
}
|
|
70
|
-
const url = this.buildUrl(null);
|
|
71
|
-
const response = await fetch(url, {
|
|
72
|
-
method: "POST",
|
|
73
|
-
headers: this.headers,
|
|
74
|
-
body: JSON.stringify(body)
|
|
75
|
-
});
|
|
76
|
-
if (!response.ok) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Failed to create ${url.toString()}: ${response.statusText}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const data = await response.json();
|
|
82
|
-
return data;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Retrieve a specific resource by ID.
|
|
86
|
-
* @param id - The ID of the resource to retrieve.
|
|
87
|
-
* @returns A promise that resolves to the retrieved resource.
|
|
88
|
-
* @throws If id is not provided or if the fetch request fails.
|
|
89
|
-
*/
|
|
90
|
-
async retrieve(id) {
|
|
91
|
-
if (!id) {
|
|
92
|
-
throw new Error("ID is required to retrieve a resource.");
|
|
93
|
-
}
|
|
94
|
-
const url = this.buildUrl(id);
|
|
95
|
-
const response = await fetch(url, {
|
|
96
|
-
method: "GET",
|
|
97
|
-
headers: this.headers
|
|
98
|
-
});
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Failed to retrieve ${url.toString()}: ${response.statusText}`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
const data = await response.json();
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Update a specific resource by ID.
|
|
109
|
-
* @param id - The ID of the resource to update.
|
|
110
|
-
* @param body - The request body containing updated resource details.
|
|
111
|
-
* @returns A promise that resolves to the updated resource.
|
|
112
|
-
* @throws If id is not provided, if body is not an object, or if the fetch request fails.
|
|
113
|
-
*/
|
|
114
|
-
async update(id, body) {
|
|
115
|
-
if (!id) {
|
|
116
|
-
throw new Error("ID is required to update a resource.");
|
|
117
|
-
}
|
|
118
|
-
if (!isObject(body)) {
|
|
119
|
-
throw new Error("Request body must be an object.");
|
|
120
|
-
}
|
|
121
|
-
const url = this.buildUrl(id);
|
|
122
|
-
const response = await fetch(url, {
|
|
123
|
-
method: "PATCH",
|
|
124
|
-
headers: this.headers,
|
|
125
|
-
body: JSON.stringify(body)
|
|
126
|
-
});
|
|
127
|
-
if (!response.ok) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
`Failed to update ${url.toString()}: ${response.statusText}`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
const data = await response.json();
|
|
133
|
-
return data;
|
|
5
|
+
function isEmpty(value) {
|
|
6
|
+
if (value === null || value === void 0) {
|
|
7
|
+
return true;
|
|
134
8
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
* @param id - The ID of the resource to delete.
|
|
138
|
-
* @returns A promise that resolves when the resource is deleted.
|
|
139
|
-
* @throws If id is not provided or if the fetch request fails.
|
|
140
|
-
*/
|
|
141
|
-
async del(id) {
|
|
142
|
-
if (!id) {
|
|
143
|
-
throw new Error("ID is required to delete a resource.");
|
|
144
|
-
}
|
|
145
|
-
const url = this.buildUrl(id);
|
|
146
|
-
const response = await fetch(url, {
|
|
147
|
-
method: "DELETE",
|
|
148
|
-
headers: this.headers
|
|
149
|
-
});
|
|
150
|
-
if (!response.ok) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
`Failed to delete ${url.toString()}: ${response.statusText}`
|
|
153
|
-
);
|
|
154
|
-
}
|
|
9
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
10
|
+
return value.length === 0;
|
|
155
11
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// src/connection.ts
|
|
159
|
-
var Connections = class extends Base {
|
|
160
|
-
constructor() {
|
|
161
|
-
super(...arguments);
|
|
162
|
-
this.namespace = "connections";
|
|
12
|
+
if (isObject(value)) {
|
|
13
|
+
return Object.keys(value).length === 0;
|
|
163
14
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// src/integration.ts
|
|
167
|
-
var Integrations = class extends Base {
|
|
168
|
-
constructor() {
|
|
169
|
-
super(...arguments);
|
|
170
|
-
this.namespace = "integrations";
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// src/webhooks.ts
|
|
175
|
-
var Webhooks = class extends Base {
|
|
176
|
-
constructor() {
|
|
177
|
-
super(...arguments);
|
|
178
|
-
this.namespace = "webhooks";
|
|
179
|
-
}
|
|
180
|
-
};
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
181
17
|
|
|
182
18
|
// src/proxy.ts
|
|
183
19
|
var Proxy = class {
|
|
@@ -193,89 +29,73 @@ var Proxy = class {
|
|
|
193
29
|
"BU-Connection-Id": this.connectionId
|
|
194
30
|
};
|
|
195
31
|
}
|
|
196
|
-
buildUrl(path
|
|
197
|
-
if (
|
|
32
|
+
buildUrl(path) {
|
|
33
|
+
if (isEmpty(path)) {
|
|
198
34
|
throw new Error("Path is required to build URL.");
|
|
199
35
|
}
|
|
200
|
-
if (!isObject(searchParams)) {
|
|
201
|
-
throw new Error("URL search params must be an object.");
|
|
202
|
-
}
|
|
203
36
|
if (!path.startsWith("/")) {
|
|
204
37
|
path = `/${path}`;
|
|
205
38
|
}
|
|
206
39
|
const url = new URL(path, this.baseUrl);
|
|
207
|
-
url.search = new URLSearchParams(searchParams).toString();
|
|
208
40
|
return url;
|
|
209
41
|
}
|
|
210
|
-
get(path,
|
|
211
|
-
if (
|
|
42
|
+
get(path, headers = {}) {
|
|
43
|
+
if (isEmpty(path)) {
|
|
212
44
|
throw new Error("Path is required for GET request.");
|
|
213
45
|
}
|
|
214
46
|
if (!isObject(headers)) {
|
|
215
47
|
throw new Error("Headers must be an object.");
|
|
216
48
|
}
|
|
217
|
-
|
|
218
|
-
throw new Error("URL search params must be an object.");
|
|
219
|
-
}
|
|
220
|
-
const url = this.buildUrl(path, searchParams);
|
|
49
|
+
const url = this.buildUrl(path);
|
|
221
50
|
return fetch(url, {
|
|
222
51
|
method: "GET",
|
|
223
52
|
headers: { ...this.headers, ...headers }
|
|
224
53
|
});
|
|
225
54
|
}
|
|
226
|
-
post(path, body
|
|
227
|
-
if (
|
|
55
|
+
post(path, body, headers = {}) {
|
|
56
|
+
if (isEmpty(path)) {
|
|
228
57
|
throw new Error("Path is required for POST request.");
|
|
229
58
|
}
|
|
230
59
|
if (!isObject(headers)) {
|
|
231
60
|
throw new Error("Headers must be an object.");
|
|
232
61
|
}
|
|
233
|
-
if (!isObject(body)) {
|
|
234
|
-
throw new Error("Request body must be an object.");
|
|
235
|
-
}
|
|
236
62
|
const url = this.buildUrl(path);
|
|
237
63
|
return fetch(url, {
|
|
64
|
+
body,
|
|
238
65
|
method: "POST",
|
|
239
|
-
headers: { ...this.headers, ...headers }
|
|
240
|
-
body: JSON.stringify(body)
|
|
66
|
+
headers: { ...this.headers, ...headers }
|
|
241
67
|
});
|
|
242
68
|
}
|
|
243
|
-
put(path, body
|
|
244
|
-
if (
|
|
69
|
+
put(path, body, headers = {}) {
|
|
70
|
+
if (isEmpty(path)) {
|
|
245
71
|
throw new Error("Path is required for PUT request.");
|
|
246
72
|
}
|
|
247
73
|
if (!isObject(headers)) {
|
|
248
74
|
throw new Error("Headers must be an object.");
|
|
249
75
|
}
|
|
250
|
-
if (!isObject(body)) {
|
|
251
|
-
throw new Error("Request body must be an object.");
|
|
252
|
-
}
|
|
253
76
|
const url = this.buildUrl(path);
|
|
254
77
|
return fetch(url, {
|
|
78
|
+
body,
|
|
255
79
|
method: "PUT",
|
|
256
|
-
headers: { ...this.headers, ...headers }
|
|
257
|
-
body: JSON.stringify(body)
|
|
80
|
+
headers: { ...this.headers, ...headers }
|
|
258
81
|
});
|
|
259
82
|
}
|
|
260
|
-
patch(path, body
|
|
261
|
-
if (
|
|
83
|
+
patch(path, body, headers = {}) {
|
|
84
|
+
if (isEmpty(path)) {
|
|
262
85
|
throw new Error("Path is required for PATCH request.");
|
|
263
86
|
}
|
|
264
87
|
if (!isObject(headers)) {
|
|
265
88
|
throw new Error("Headers must be an object.");
|
|
266
89
|
}
|
|
267
|
-
if (!isObject(body)) {
|
|
268
|
-
throw new Error("Request body must be an object.");
|
|
269
|
-
}
|
|
270
90
|
const url = this.buildUrl(path);
|
|
271
91
|
return fetch(url, {
|
|
92
|
+
body,
|
|
272
93
|
method: "PATCH",
|
|
273
|
-
headers: { ...this.headers, ...headers }
|
|
274
|
-
body: JSON.stringify(body)
|
|
94
|
+
headers: { ...this.headers, ...headers }
|
|
275
95
|
});
|
|
276
96
|
}
|
|
277
97
|
delete(path, headers = {}) {
|
|
278
|
-
if (
|
|
98
|
+
if (isEmpty(path)) {
|
|
279
99
|
throw new Error("Path is required for DELETE request.");
|
|
280
100
|
}
|
|
281
101
|
if (!isObject(headers)) {
|
|
@@ -289,39 +109,8 @@ var Proxy = class {
|
|
|
289
109
|
}
|
|
290
110
|
};
|
|
291
111
|
|
|
292
|
-
// src/session.ts
|
|
293
|
-
var Sessions = class {
|
|
294
|
-
constructor(apiKey) {
|
|
295
|
-
this.apiKey = apiKey;
|
|
296
|
-
}
|
|
297
|
-
get headers() {
|
|
298
|
-
return {
|
|
299
|
-
"Content-Type": "application/json",
|
|
300
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Create a new session.
|
|
305
|
-
* @param params - The session creation parameters.
|
|
306
|
-
* @returns A promise that resolves to the created session details.
|
|
307
|
-
* @throws If the fetch request fails.
|
|
308
|
-
*/
|
|
309
|
-
async create(params) {
|
|
310
|
-
const response = await fetch("https://api.bundleup.io/v1/sessions", {
|
|
311
|
-
method: "POST",
|
|
312
|
-
headers: this.headers,
|
|
313
|
-
body: JSON.stringify(params)
|
|
314
|
-
});
|
|
315
|
-
if (!response.ok) {
|
|
316
|
-
throw new Error("Failed to create session");
|
|
317
|
-
}
|
|
318
|
-
const data = await response.json();
|
|
319
|
-
return data;
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
|
|
323
112
|
// src/unify/base.ts
|
|
324
|
-
var
|
|
113
|
+
var Base = class {
|
|
325
114
|
constructor(apiKey, connectionId) {
|
|
326
115
|
this.apiKey = apiKey;
|
|
327
116
|
this.connectionId = connectionId;
|
|
@@ -340,23 +129,23 @@ var Base2 = class {
|
|
|
340
129
|
throw new Error("URL search params must be an object.");
|
|
341
130
|
}
|
|
342
131
|
const parts = [this.version, this.namespace, path].filter(Boolean).join("/");
|
|
343
|
-
|
|
132
|
+
const parsedSearchParams = Object.entries(searchParams).reduce(
|
|
344
133
|
(acc, [key, value]) => {
|
|
345
134
|
if (value !== void 0 && value !== null) {
|
|
346
|
-
acc[key] = value;
|
|
135
|
+
acc[key] = value.toString();
|
|
347
136
|
}
|
|
348
137
|
return acc;
|
|
349
138
|
},
|
|
350
139
|
{}
|
|
351
140
|
);
|
|
352
141
|
const url = new URL(parts, this.baseUrl);
|
|
353
|
-
url.search = new URLSearchParams(
|
|
142
|
+
url.search = new URLSearchParams(parsedSearchParams).toString();
|
|
354
143
|
return url;
|
|
355
144
|
}
|
|
356
145
|
};
|
|
357
146
|
|
|
358
147
|
// src/unify/chat.ts
|
|
359
|
-
var Chat = class extends
|
|
148
|
+
var Chat = class extends Base {
|
|
360
149
|
constructor() {
|
|
361
150
|
super(...arguments);
|
|
362
151
|
this.namespace = "chat";
|
|
@@ -365,21 +154,14 @@ var Chat = class extends Base2 {
|
|
|
365
154
|
* Fetch chat channels
|
|
366
155
|
* @param limit - Maximum number of channels to retrieve.
|
|
367
156
|
* @param after - Cursor for pagination.
|
|
368
|
-
* @param
|
|
157
|
+
* @param include_raw - Whether to include raw response data.
|
|
369
158
|
* @returns A promise that resolves to the fetch response.
|
|
370
159
|
*/
|
|
371
|
-
async channels({ limit = 100, after,
|
|
372
|
-
const url = this.buildUrl("channels", { limit, after });
|
|
373
|
-
const response = await fetch(url, {
|
|
374
|
-
headers: {
|
|
375
|
-
...this.headers,
|
|
376
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
377
|
-
}
|
|
378
|
-
});
|
|
160
|
+
async channels({ limit = 100, after, include_raw = false } = {}) {
|
|
161
|
+
const url = this.buildUrl("channels", { limit, after, include_raw });
|
|
162
|
+
const response = await fetch(url, { headers: this.headers });
|
|
379
163
|
if (!response.ok) {
|
|
380
|
-
throw new Error(
|
|
381
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
382
|
-
);
|
|
164
|
+
throw new Error(`Failed to fetch ${this.namespace}/channels: ${response.statusText}`);
|
|
383
165
|
}
|
|
384
166
|
const data = await response.json();
|
|
385
167
|
return data;
|
|
@@ -387,7 +169,7 @@ var Chat = class extends Base2 {
|
|
|
387
169
|
};
|
|
388
170
|
|
|
389
171
|
// src/unify/git.ts
|
|
390
|
-
var Git = class extends
|
|
172
|
+
var Git = class extends Base {
|
|
391
173
|
constructor() {
|
|
392
174
|
super(...arguments);
|
|
393
175
|
this.namespace = "git";
|
|
@@ -399,18 +181,11 @@ var Git = class extends Base2 {
|
|
|
399
181
|
* @param includeRaw - Whether to include raw response data.
|
|
400
182
|
* @returns A promise that resolves to the fetch response.
|
|
401
183
|
*/
|
|
402
|
-
async repos({ limit = 100, after,
|
|
403
|
-
const url = this.buildUrl("repos", { limit, after });
|
|
404
|
-
const response = await fetch(url, {
|
|
405
|
-
headers: {
|
|
406
|
-
...this.headers,
|
|
407
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
408
|
-
}
|
|
409
|
-
});
|
|
184
|
+
async repos({ limit = 100, after, include_raw = false } = {}) {
|
|
185
|
+
const url = this.buildUrl("repos", { limit, after, include_raw });
|
|
186
|
+
const response = await fetch(url, { headers: this.headers });
|
|
410
187
|
if (!response.ok) {
|
|
411
|
-
throw new Error(
|
|
412
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
413
|
-
);
|
|
188
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos: ${response.statusText}`);
|
|
414
189
|
}
|
|
415
190
|
const data = await response.json();
|
|
416
191
|
return data;
|
|
@@ -420,28 +195,22 @@ var Git = class extends Base2 {
|
|
|
420
195
|
* @param repoName - The name of the repository.
|
|
421
196
|
* @param limit - Maximum number of pull requests to retrieve.
|
|
422
197
|
* @param after - Cursor for pagination.
|
|
423
|
-
* @param
|
|
198
|
+
* @param include_raw - Whether to include raw response data.
|
|
424
199
|
* @returns A promise that resolves to the fetch response.
|
|
425
200
|
* @throws If repoName is not provided.
|
|
426
201
|
*/
|
|
427
|
-
async pulls(
|
|
202
|
+
async pulls(repoName, { limit = 100, after, include_raw = false }) {
|
|
428
203
|
if (!repoName) {
|
|
429
204
|
throw new Error("repoName is required to fetch pulls.");
|
|
430
205
|
}
|
|
431
206
|
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/pulls`, {
|
|
432
207
|
limit,
|
|
433
|
-
after
|
|
434
|
-
|
|
435
|
-
const response = await fetch(url, {
|
|
436
|
-
headers: {
|
|
437
|
-
...this.headers,
|
|
438
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
439
|
-
}
|
|
208
|
+
after,
|
|
209
|
+
include_raw
|
|
440
210
|
});
|
|
211
|
+
const response = await fetch(url, { headers: this.headers });
|
|
441
212
|
if (!response.ok) {
|
|
442
|
-
throw new Error(
|
|
443
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
444
|
-
);
|
|
213
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/pulls: ${response.statusText}`);
|
|
445
214
|
}
|
|
446
215
|
const data = await response.json();
|
|
447
216
|
return data;
|
|
@@ -451,28 +220,22 @@ var Git = class extends Base2 {
|
|
|
451
220
|
* @param repoName - The name of the repository.
|
|
452
221
|
* @param limit - Maximum number of tags to retrieve.
|
|
453
222
|
* @param after - Cursor for pagination.
|
|
454
|
-
* @param
|
|
223
|
+
* @param include_raw - Whether to include raw response data.
|
|
455
224
|
* @returns A promise that resolves to the fetch response.
|
|
456
225
|
* @throws If repoName is not provided.
|
|
457
226
|
*/
|
|
458
|
-
async tags(
|
|
227
|
+
async tags(repoName, { limit = 100, after, include_raw = false }) {
|
|
459
228
|
if (!repoName) {
|
|
460
229
|
throw new Error("repoName is required to fetch tags.");
|
|
461
230
|
}
|
|
462
231
|
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/tags`, {
|
|
463
232
|
limit,
|
|
464
|
-
after
|
|
465
|
-
|
|
466
|
-
const response = await fetch(url, {
|
|
467
|
-
headers: {
|
|
468
|
-
...this.headers,
|
|
469
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
470
|
-
}
|
|
233
|
+
after,
|
|
234
|
+
include_raw
|
|
471
235
|
});
|
|
236
|
+
const response = await fetch(url, { headers: this.headers });
|
|
472
237
|
if (!response.ok) {
|
|
473
|
-
throw new Error(
|
|
474
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
475
|
-
);
|
|
238
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/tags: ${response.statusText}`);
|
|
476
239
|
}
|
|
477
240
|
const data = await response.json();
|
|
478
241
|
return data;
|
|
@@ -482,31 +245,22 @@ var Git = class extends Base2 {
|
|
|
482
245
|
* @param repoName - The name of the repository.
|
|
483
246
|
* @param limit - Maximum number of releases to retrieve.
|
|
484
247
|
* @param after - Cursor for pagination.
|
|
485
|
-
* @param
|
|
248
|
+
* @param include_raw - Whether to include raw response data.
|
|
486
249
|
* @returns A promise that resolves to the fetch response.
|
|
487
250
|
* @throws If repoName is not provided.
|
|
488
251
|
*/
|
|
489
|
-
async releases(
|
|
252
|
+
async releases(repoName, { limit = 100, after, include_raw = false }) {
|
|
490
253
|
if (!repoName) {
|
|
491
254
|
throw new Error("repoName is required to fetch releases.");
|
|
492
255
|
}
|
|
493
|
-
const url = this.buildUrl(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
after
|
|
498
|
-
}
|
|
499
|
-
);
|
|
500
|
-
const response = await fetch(url, {
|
|
501
|
-
headers: {
|
|
502
|
-
...this.headers,
|
|
503
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
504
|
-
}
|
|
256
|
+
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/releases`, {
|
|
257
|
+
limit,
|
|
258
|
+
after,
|
|
259
|
+
include_raw
|
|
505
260
|
});
|
|
261
|
+
const response = await fetch(url, { headers: this.headers });
|
|
506
262
|
if (!response.ok) {
|
|
507
|
-
throw new Error(
|
|
508
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
509
|
-
);
|
|
263
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/releases: ${response.statusText}`);
|
|
510
264
|
}
|
|
511
265
|
const data = await response.json();
|
|
512
266
|
return data;
|
|
@@ -514,7 +268,7 @@ var Git = class extends Base2 {
|
|
|
514
268
|
};
|
|
515
269
|
|
|
516
270
|
// src/unify/pm.ts
|
|
517
|
-
var PM = class extends
|
|
271
|
+
var PM = class extends Base {
|
|
518
272
|
constructor() {
|
|
519
273
|
super(...arguments);
|
|
520
274
|
this.namespace = "pm";
|
|
@@ -523,31 +277,317 @@ var PM = class extends Base2 {
|
|
|
523
277
|
* Fetch issues
|
|
524
278
|
* @param limit - Maximum number of issues to retrieve.
|
|
525
279
|
* @param after - Cursor for pagination.
|
|
526
|
-
* @param
|
|
280
|
+
* @param include_raw - Whether to include raw response data.
|
|
527
281
|
* @returns A promise that resolves to the fetch response.
|
|
528
282
|
*/
|
|
529
|
-
async issues({ limit = 100, after,
|
|
530
|
-
const url = this.buildUrl("issues", { limit, after });
|
|
283
|
+
async issues({ limit = 100, after, include_raw = false } = {}) {
|
|
284
|
+
const url = this.buildUrl("issues", { limit, after, include_raw });
|
|
285
|
+
const response = await fetch(url, { headers: this.headers });
|
|
286
|
+
if (!response.ok) {
|
|
287
|
+
throw new Error(`Failed to fetch ${this.namespace}/issues: ${response.statusText}`);
|
|
288
|
+
}
|
|
289
|
+
const data = await response.json();
|
|
290
|
+
return data;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/unify.ts
|
|
295
|
+
var Unify = class {
|
|
296
|
+
constructor(apiKey, connectionId) {
|
|
297
|
+
this.apiKey = apiKey;
|
|
298
|
+
this.connectionId = connectionId;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Access the Chat API for the connection.
|
|
302
|
+
*/
|
|
303
|
+
get chat() {
|
|
304
|
+
return new Chat(this.apiKey, this.connectionId);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Access the Git API for the connection.
|
|
308
|
+
*/
|
|
309
|
+
get git() {
|
|
310
|
+
return new Git(this.apiKey, this.connectionId);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Access the PM API for the connection.
|
|
314
|
+
*/
|
|
315
|
+
get pm() {
|
|
316
|
+
return new PM(this.apiKey, this.connectionId);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/resources/base.ts
|
|
321
|
+
var Base2 = class {
|
|
322
|
+
constructor(apiKey) {
|
|
323
|
+
this.apiKey = apiKey;
|
|
324
|
+
this.baseUrl = "https://api.bundleup.io";
|
|
325
|
+
this.version = "v1";
|
|
326
|
+
}
|
|
327
|
+
buildUrl(path, searchParams = {}) {
|
|
328
|
+
if (!isObject(searchParams)) {
|
|
329
|
+
throw new Error("URL search params must be an object.");
|
|
330
|
+
}
|
|
331
|
+
const parts = [this.version, this.namespace, path].filter(Boolean).join("/");
|
|
332
|
+
const urlParams = Object.entries(searchParams).reduce(
|
|
333
|
+
(acc, [key, value]) => {
|
|
334
|
+
if (value !== void 0 && value !== null) {
|
|
335
|
+
acc[key] = value.toString();
|
|
336
|
+
}
|
|
337
|
+
return acc;
|
|
338
|
+
},
|
|
339
|
+
{}
|
|
340
|
+
);
|
|
341
|
+
const url = new URL(parts, this.baseUrl);
|
|
342
|
+
url.search = new URLSearchParams(urlParams).toString();
|
|
343
|
+
return url;
|
|
344
|
+
}
|
|
345
|
+
get headers() {
|
|
346
|
+
return {
|
|
347
|
+
"Content-Type": "application/json",
|
|
348
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* List resources with optional query parameters.
|
|
353
|
+
* @param searchParams - Query parameters for filtering the list.
|
|
354
|
+
* @returns A promise that resolves to an array of resources.
|
|
355
|
+
* @throws If params is not an object or if the fetch request fails.
|
|
356
|
+
*/
|
|
357
|
+
async list(searchParams = {}) {
|
|
358
|
+
if (!isObject(searchParams)) {
|
|
359
|
+
throw new Error("List parameters must be an object.");
|
|
360
|
+
}
|
|
361
|
+
const url = this.buildUrl(null, searchParams);
|
|
362
|
+
const response = await fetch(url, {
|
|
363
|
+
method: "GET",
|
|
364
|
+
headers: this.headers
|
|
365
|
+
});
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`Failed to fetch ${this.namespace}: ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
const data = await response.json();
|
|
370
|
+
return data;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Create a new resource.
|
|
374
|
+
* @param body - The request body containing resource details.
|
|
375
|
+
* @returns A promise that resolves to the created resource.
|
|
376
|
+
* @throws If body is not an object or if the fetch request fails.
|
|
377
|
+
*/
|
|
378
|
+
async create(body) {
|
|
379
|
+
if (!isObject(body)) {
|
|
380
|
+
throw new Error("Request body must be an object.");
|
|
381
|
+
}
|
|
382
|
+
const url = this.buildUrl(null);
|
|
383
|
+
const response = await fetch(url, {
|
|
384
|
+
method: "POST",
|
|
385
|
+
headers: this.headers,
|
|
386
|
+
body: JSON.stringify(body)
|
|
387
|
+
});
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
throw new Error(`Failed to create ${this.namespace}: ${response.statusText}`);
|
|
390
|
+
}
|
|
391
|
+
const data = await response.json();
|
|
392
|
+
return data;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Retrieve a specific resource by ID.
|
|
396
|
+
* @param id - The ID of the resource to retrieve.
|
|
397
|
+
* @returns A promise that resolves to the retrieved resource.
|
|
398
|
+
* @throws If id is not provided or if the fetch request fails.
|
|
399
|
+
*/
|
|
400
|
+
async retrieve(id) {
|
|
401
|
+
if (isEmpty(id)) {
|
|
402
|
+
throw new Error("ID is required to retrieve a resource.");
|
|
403
|
+
}
|
|
404
|
+
const url = this.buildUrl(id);
|
|
531
405
|
const response = await fetch(url, {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
535
|
-
}
|
|
406
|
+
method: "GET",
|
|
407
|
+
headers: this.headers
|
|
536
408
|
});
|
|
537
409
|
if (!response.ok) {
|
|
538
|
-
throw new Error(
|
|
539
|
-
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
540
|
-
);
|
|
410
|
+
throw new Error(`Failed to retrieve ${this.namespace}: ${response.statusText}`);
|
|
541
411
|
}
|
|
542
412
|
const data = await response.json();
|
|
543
413
|
return data;
|
|
544
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Update a specific resource by ID.
|
|
417
|
+
* @param id - The ID of the resource to update.
|
|
418
|
+
* @param body - The request body containing updated resource details.
|
|
419
|
+
* @returns A promise that resolves to the updated resource.
|
|
420
|
+
* @throws If id is not provided, if body is not an object, or if the fetch request fails.
|
|
421
|
+
*/
|
|
422
|
+
async update(id, body) {
|
|
423
|
+
if (isEmpty(id)) {
|
|
424
|
+
throw new Error("ID is required to update a resource.");
|
|
425
|
+
}
|
|
426
|
+
if (!isObject(body)) {
|
|
427
|
+
throw new Error("Request body must be an object.");
|
|
428
|
+
}
|
|
429
|
+
const url = this.buildUrl(id);
|
|
430
|
+
const response = await fetch(url, {
|
|
431
|
+
method: "PATCH",
|
|
432
|
+
headers: this.headers,
|
|
433
|
+
body: JSON.stringify(body)
|
|
434
|
+
});
|
|
435
|
+
if (!response.ok) {
|
|
436
|
+
throw new Error(`Failed to update ${this.namespace}: ${response.statusText}`);
|
|
437
|
+
}
|
|
438
|
+
const data = await response.json();
|
|
439
|
+
return data;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Delete a specific resource by ID.
|
|
443
|
+
* @param id - The ID of the resource to delete.
|
|
444
|
+
* @returns A promise that resolves when the resource is deleted.
|
|
445
|
+
* @throws If id is not provided or if the fetch request fails.
|
|
446
|
+
*/
|
|
447
|
+
async del(id) {
|
|
448
|
+
if (isEmpty(id)) {
|
|
449
|
+
throw new Error("ID is required to delete a resource.");
|
|
450
|
+
}
|
|
451
|
+
const url = this.buildUrl(id);
|
|
452
|
+
const response = await fetch(url, {
|
|
453
|
+
method: "DELETE",
|
|
454
|
+
headers: this.headers
|
|
455
|
+
});
|
|
456
|
+
if (!response.ok) {
|
|
457
|
+
throw new Error(`Failed to delete ${this.namespace}: ${response.statusText}`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/resources/connection.ts
|
|
463
|
+
var Connections = class extends Base2 {
|
|
464
|
+
constructor() {
|
|
465
|
+
super(...arguments);
|
|
466
|
+
this.namespace = "connections";
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* List all connections with optional query parameters.
|
|
470
|
+
* @param searchParams - Query parameters for filtering the list of connections.
|
|
471
|
+
* - offset: The number of items to skip before starting to collect the result set.
|
|
472
|
+
* - limit: The number of items to return.
|
|
473
|
+
* - integration_id: Filter connections by integration ID.
|
|
474
|
+
* - integration_identifier: Filter connections by integration identifier.
|
|
475
|
+
* - external_id: Filter connections by external ID.
|
|
476
|
+
* @returns A promise that resolves to an array of connection objects.
|
|
477
|
+
* @throws If the fetch request fails or if the search parameters are invalid.
|
|
478
|
+
*/
|
|
479
|
+
list(searchParams = {}) {
|
|
480
|
+
return super.list(searchParams);
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Retrieve a specific connection by ID.
|
|
484
|
+
* @param id - The ID of the connection to retrieve.
|
|
485
|
+
* @returns A promise that resolves to the connection object.
|
|
486
|
+
* @throws If the fetch request fails or if the ID is invalid.
|
|
487
|
+
*/
|
|
488
|
+
retrieve(id) {
|
|
489
|
+
return super.retrieve(id);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Delete a specific connection by ID.
|
|
493
|
+
* @param id - The ID of the connection to delete.
|
|
494
|
+
* @returns A promise that resolves when the connection is deleted.
|
|
495
|
+
* @throws If the fetch request fails or if the ID is invalid.
|
|
496
|
+
*/
|
|
497
|
+
del(id) {
|
|
498
|
+
return super.del(id);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/resources/integration.ts
|
|
503
|
+
var Integrations = class extends Base2 {
|
|
504
|
+
constructor() {
|
|
505
|
+
super(...arguments);
|
|
506
|
+
this.namespace = "integrations";
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* List all integrations with optional query parameters.
|
|
510
|
+
* @param searchParams - Query parameters for filtering the list of integrations.
|
|
511
|
+
* - offset: The number of items to skip before starting to collect the result set.
|
|
512
|
+
* - limit: The number of items to return.
|
|
513
|
+
* - status: Filter integrations by status (e.g., 'active', 'inactive').
|
|
514
|
+
* @returns A promise that resolves to an array of integration objects.
|
|
515
|
+
* @throws If the fetch request fails or if the search parameters are invalid.
|
|
516
|
+
*/
|
|
517
|
+
list(searchParams = {}) {
|
|
518
|
+
return super.list(searchParams);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Retrieve a specific integration by ID.
|
|
522
|
+
* @param id - The ID of the integration to retrieve.
|
|
523
|
+
* @returns A promise that resolves to the integration object.
|
|
524
|
+
* @throws If the fetch request fails or if the ID is invalid.
|
|
525
|
+
*/
|
|
526
|
+
retrieve(id) {
|
|
527
|
+
return super.retrieve(id);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
// src/resources/webhooks.ts
|
|
532
|
+
var Webhooks = class extends Base2 {
|
|
533
|
+
constructor() {
|
|
534
|
+
super(...arguments);
|
|
535
|
+
this.namespace = "webhooks";
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* List all webhooks with optional query parameters.
|
|
539
|
+
* @param searchParams - Query parameters for filtering the list of webhooks.
|
|
540
|
+
* - offset: The number of items to skip before starting to collect the result set.
|
|
541
|
+
* - limit: The number of items to return.
|
|
542
|
+
* @returns A promise that resolves to an array of webhook objects.
|
|
543
|
+
* @throws If the fetch request fails or if the search parameters are invalid.
|
|
544
|
+
*/
|
|
545
|
+
list(searchParams = {}) {
|
|
546
|
+
return super.list(searchParams);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Retrieve a specific webhook by ID.
|
|
550
|
+
* @param id - The ID of the webhook to retrieve.
|
|
551
|
+
* @returns A promise that resolves to the webhook object.
|
|
552
|
+
* @throws If the fetch request fails or if the ID is invalid.
|
|
553
|
+
*/
|
|
554
|
+
retrieve(id) {
|
|
555
|
+
return super.retrieve(id);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Create a new webhook with the specified data.
|
|
559
|
+
* @param data - An object containing the properties of the webhook to create.
|
|
560
|
+
* @returns A promise that resolves to the created webhook object.
|
|
561
|
+
* @throws If the fetch request fails or if the data is invalid.
|
|
562
|
+
*/
|
|
563
|
+
create(data) {
|
|
564
|
+
return super.create(data);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Update an existing webhook with the specified data.
|
|
568
|
+
* @param id - The ID of the webhook to update.
|
|
569
|
+
* @param data - An object containing the properties of the webhook to update.
|
|
570
|
+
* @returns A promise that resolves to the updated webhook object.
|
|
571
|
+
* @throws If the fetch request fails, if the ID is invalid, or if the data is invalid.
|
|
572
|
+
*/
|
|
573
|
+
update(id, data) {
|
|
574
|
+
return super.update(id, data);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Delete a specific webhook by ID.
|
|
578
|
+
* @param id - The ID of the webhook to delete.
|
|
579
|
+
* @returns A promise that resolves when the webhook is deleted.
|
|
580
|
+
* @throws If the fetch request fails or if the ID is invalid.
|
|
581
|
+
*/
|
|
582
|
+
del(id) {
|
|
583
|
+
return super.del(id);
|
|
584
|
+
}
|
|
545
585
|
};
|
|
546
586
|
|
|
547
587
|
// src/index.ts
|
|
548
588
|
var BundleUp = class {
|
|
549
589
|
constructor(apiKey) {
|
|
550
|
-
if (
|
|
590
|
+
if (isEmpty(apiKey)) {
|
|
551
591
|
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
552
592
|
}
|
|
553
593
|
this.apiKey = apiKey;
|
|
@@ -570,19 +610,13 @@ var BundleUp = class {
|
|
|
570
610
|
get webhooks() {
|
|
571
611
|
return new Webhooks(this.apiKey);
|
|
572
612
|
}
|
|
573
|
-
/**
|
|
574
|
-
* Access the Sessions resource.
|
|
575
|
-
*/
|
|
576
|
-
get sessions() {
|
|
577
|
-
return new Sessions(this.apiKey);
|
|
578
|
-
}
|
|
579
613
|
/**
|
|
580
614
|
* Create a Proxy instance for a specific connection.
|
|
581
615
|
* @param connectionId - The ID of the connection.
|
|
582
616
|
* @returns A Proxy instance.
|
|
583
617
|
*/
|
|
584
618
|
proxy(connectionId) {
|
|
585
|
-
if (
|
|
619
|
+
if (isEmpty(connectionId)) {
|
|
586
620
|
throw new Error("Connection ID is required to create a Proxy instance.");
|
|
587
621
|
}
|
|
588
622
|
return new Proxy(this.apiKey, connectionId);
|
|
@@ -593,14 +627,10 @@ var BundleUp = class {
|
|
|
593
627
|
* @returns An object containing Unify methods.
|
|
594
628
|
*/
|
|
595
629
|
unify(connectionId) {
|
|
596
|
-
if (
|
|
630
|
+
if (isEmpty(connectionId)) {
|
|
597
631
|
throw new Error("Connection ID is required to create a Unify instance.");
|
|
598
632
|
}
|
|
599
|
-
return
|
|
600
|
-
chat: new Chat(this.apiKey, connectionId),
|
|
601
|
-
git: new Git(this.apiKey, connectionId),
|
|
602
|
-
pm: new PM(this.apiKey, connectionId)
|
|
603
|
-
};
|
|
633
|
+
return new Unify(this.apiKey, connectionId);
|
|
604
634
|
}
|
|
605
635
|
};
|
|
606
636
|
export {
|