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