@bundleup/sdk 0.0.18 → 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 +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.mjs
CHANGED
|
@@ -2,172 +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(`Failed to fetch ${url.toString()}: ${response.statusText}`);
|
|
54
|
-
}
|
|
55
|
-
const data = await response.json();
|
|
56
|
-
return data;
|
|
5
|
+
function isEmpty(value) {
|
|
6
|
+
if (value === null || value === void 0) {
|
|
7
|
+
return true;
|
|
57
8
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* @param body - The request body containing resource details.
|
|
61
|
-
* @returns A promise that resolves to the created resource.
|
|
62
|
-
* @throws If body is not an object or if the fetch request fails.
|
|
63
|
-
*/
|
|
64
|
-
async create(body) {
|
|
65
|
-
if (!isObject(body)) {
|
|
66
|
-
throw new Error("Request body must be an object.");
|
|
67
|
-
}
|
|
68
|
-
const url = this.buildUrl(null);
|
|
69
|
-
const response = await fetch(url, {
|
|
70
|
-
method: "POST",
|
|
71
|
-
headers: this.headers,
|
|
72
|
-
body: JSON.stringify(body)
|
|
73
|
-
});
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
throw new Error(`Failed to create ${url.toString()}: ${response.statusText}`);
|
|
76
|
-
}
|
|
77
|
-
const data = await response.json();
|
|
78
|
-
return data;
|
|
9
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
10
|
+
return value.length === 0;
|
|
79
11
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @param id - The ID of the resource to retrieve.
|
|
83
|
-
* @returns A promise that resolves to the retrieved resource.
|
|
84
|
-
* @throws If id is not provided or if the fetch request fails.
|
|
85
|
-
*/
|
|
86
|
-
async retrieve(id) {
|
|
87
|
-
if (!id) {
|
|
88
|
-
throw new Error("ID is required to retrieve a resource.");
|
|
89
|
-
}
|
|
90
|
-
const url = this.buildUrl(id);
|
|
91
|
-
const response = await fetch(url, {
|
|
92
|
-
method: "GET",
|
|
93
|
-
headers: this.headers
|
|
94
|
-
});
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error(`Failed to retrieve ${url.toString()}: ${response.statusText}`);
|
|
97
|
-
}
|
|
98
|
-
const data = await response.json();
|
|
99
|
-
return data;
|
|
12
|
+
if (isObject(value)) {
|
|
13
|
+
return Object.keys(value).length === 0;
|
|
100
14
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* @param id - The ID of the resource to update.
|
|
104
|
-
* @param body - The request body containing updated resource details.
|
|
105
|
-
* @returns A promise that resolves to the updated resource.
|
|
106
|
-
* @throws If id is not provided, if body is not an object, or if the fetch request fails.
|
|
107
|
-
*/
|
|
108
|
-
async update(id, body) {
|
|
109
|
-
if (!id) {
|
|
110
|
-
throw new Error("ID is required to update a resource.");
|
|
111
|
-
}
|
|
112
|
-
if (!isObject(body)) {
|
|
113
|
-
throw new Error("Request body must be an object.");
|
|
114
|
-
}
|
|
115
|
-
const url = this.buildUrl(id);
|
|
116
|
-
const response = await fetch(url, {
|
|
117
|
-
method: "PATCH",
|
|
118
|
-
headers: this.headers,
|
|
119
|
-
body: JSON.stringify(body)
|
|
120
|
-
});
|
|
121
|
-
if (!response.ok) {
|
|
122
|
-
throw new Error(`Failed to update ${url.toString()}: ${response.statusText}`);
|
|
123
|
-
}
|
|
124
|
-
const data = await response.json();
|
|
125
|
-
return data;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Delete a specific resource by ID.
|
|
129
|
-
* @param id - The ID of the resource to delete.
|
|
130
|
-
* @returns A promise that resolves when the resource is deleted.
|
|
131
|
-
* @throws If id is not provided or if the fetch request fails.
|
|
132
|
-
*/
|
|
133
|
-
async del(id) {
|
|
134
|
-
if (!id) {
|
|
135
|
-
throw new Error("ID is required to delete a resource.");
|
|
136
|
-
}
|
|
137
|
-
const url = this.buildUrl(id);
|
|
138
|
-
const response = await fetch(url, {
|
|
139
|
-
method: "DELETE",
|
|
140
|
-
headers: this.headers
|
|
141
|
-
});
|
|
142
|
-
if (!response.ok) {
|
|
143
|
-
throw new Error(`Failed to delete ${url.toString()}: ${response.statusText}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/connection.ts
|
|
149
|
-
var Connections = class extends Base {
|
|
150
|
-
constructor() {
|
|
151
|
-
super(...arguments);
|
|
152
|
-
this.namespace = "connections";
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
// src/integration.ts
|
|
157
|
-
var Integrations = class extends Base {
|
|
158
|
-
constructor() {
|
|
159
|
-
super(...arguments);
|
|
160
|
-
this.namespace = "integrations";
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// src/webhooks.ts
|
|
165
|
-
var Webhooks = class extends Base {
|
|
166
|
-
constructor() {
|
|
167
|
-
super(...arguments);
|
|
168
|
-
this.namespace = "webhooks";
|
|
169
|
-
}
|
|
170
|
-
};
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
171
17
|
|
|
172
18
|
// src/proxy.ts
|
|
173
19
|
var Proxy = class {
|
|
@@ -184,7 +30,7 @@ var Proxy = class {
|
|
|
184
30
|
};
|
|
185
31
|
}
|
|
186
32
|
buildUrl(path) {
|
|
187
|
-
if (
|
|
33
|
+
if (isEmpty(path)) {
|
|
188
34
|
throw new Error("Path is required to build URL.");
|
|
189
35
|
}
|
|
190
36
|
if (!path.startsWith("/")) {
|
|
@@ -194,7 +40,7 @@ var Proxy = class {
|
|
|
194
40
|
return url;
|
|
195
41
|
}
|
|
196
42
|
get(path, headers = {}) {
|
|
197
|
-
if (
|
|
43
|
+
if (isEmpty(path)) {
|
|
198
44
|
throw new Error("Path is required for GET request.");
|
|
199
45
|
}
|
|
200
46
|
if (!isObject(headers)) {
|
|
@@ -207,7 +53,7 @@ var Proxy = class {
|
|
|
207
53
|
});
|
|
208
54
|
}
|
|
209
55
|
post(path, body, headers = {}) {
|
|
210
|
-
if (
|
|
56
|
+
if (isEmpty(path)) {
|
|
211
57
|
throw new Error("Path is required for POST request.");
|
|
212
58
|
}
|
|
213
59
|
if (!isObject(headers)) {
|
|
@@ -221,7 +67,7 @@ var Proxy = class {
|
|
|
221
67
|
});
|
|
222
68
|
}
|
|
223
69
|
put(path, body, headers = {}) {
|
|
224
|
-
if (
|
|
70
|
+
if (isEmpty(path)) {
|
|
225
71
|
throw new Error("Path is required for PUT request.");
|
|
226
72
|
}
|
|
227
73
|
if (!isObject(headers)) {
|
|
@@ -235,7 +81,7 @@ var Proxy = class {
|
|
|
235
81
|
});
|
|
236
82
|
}
|
|
237
83
|
patch(path, body, headers = {}) {
|
|
238
|
-
if (
|
|
84
|
+
if (isEmpty(path)) {
|
|
239
85
|
throw new Error("Path is required for PATCH request.");
|
|
240
86
|
}
|
|
241
87
|
if (!isObject(headers)) {
|
|
@@ -249,7 +95,7 @@ var Proxy = class {
|
|
|
249
95
|
});
|
|
250
96
|
}
|
|
251
97
|
delete(path, headers = {}) {
|
|
252
|
-
if (
|
|
98
|
+
if (isEmpty(path)) {
|
|
253
99
|
throw new Error("Path is required for DELETE request.");
|
|
254
100
|
}
|
|
255
101
|
if (!isObject(headers)) {
|
|
@@ -264,7 +110,7 @@ var Proxy = class {
|
|
|
264
110
|
};
|
|
265
111
|
|
|
266
112
|
// src/unify/base.ts
|
|
267
|
-
var
|
|
113
|
+
var Base = class {
|
|
268
114
|
constructor(apiKey, connectionId) {
|
|
269
115
|
this.apiKey = apiKey;
|
|
270
116
|
this.connectionId = connectionId;
|
|
@@ -299,7 +145,7 @@ var Base2 = class {
|
|
|
299
145
|
};
|
|
300
146
|
|
|
301
147
|
// src/unify/chat.ts
|
|
302
|
-
var Chat = class extends
|
|
148
|
+
var Chat = class extends Base {
|
|
303
149
|
constructor() {
|
|
304
150
|
super(...arguments);
|
|
305
151
|
this.namespace = "chat";
|
|
@@ -308,19 +154,14 @@ var Chat = class extends Base2 {
|
|
|
308
154
|
* Fetch chat channels
|
|
309
155
|
* @param limit - Maximum number of channels to retrieve.
|
|
310
156
|
* @param after - Cursor for pagination.
|
|
311
|
-
* @param
|
|
157
|
+
* @param include_raw - Whether to include raw response data.
|
|
312
158
|
* @returns A promise that resolves to the fetch response.
|
|
313
159
|
*/
|
|
314
|
-
async channels({ limit = 100, after,
|
|
315
|
-
const url = this.buildUrl("channels", { limit, after });
|
|
316
|
-
const response = await fetch(url, {
|
|
317
|
-
headers: {
|
|
318
|
-
...this.headers,
|
|
319
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
320
|
-
}
|
|
321
|
-
});
|
|
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 });
|
|
322
163
|
if (!response.ok) {
|
|
323
|
-
throw new Error(`Failed to fetch ${
|
|
164
|
+
throw new Error(`Failed to fetch ${this.namespace}/channels: ${response.statusText}`);
|
|
324
165
|
}
|
|
325
166
|
const data = await response.json();
|
|
326
167
|
return data;
|
|
@@ -328,7 +169,7 @@ var Chat = class extends Base2 {
|
|
|
328
169
|
};
|
|
329
170
|
|
|
330
171
|
// src/unify/git.ts
|
|
331
|
-
var Git = class extends
|
|
172
|
+
var Git = class extends Base {
|
|
332
173
|
constructor() {
|
|
333
174
|
super(...arguments);
|
|
334
175
|
this.namespace = "git";
|
|
@@ -340,16 +181,11 @@ var Git = class extends Base2 {
|
|
|
340
181
|
* @param includeRaw - Whether to include raw response data.
|
|
341
182
|
* @returns A promise that resolves to the fetch response.
|
|
342
183
|
*/
|
|
343
|
-
async repos({ limit = 100, after,
|
|
344
|
-
const url = this.buildUrl("repos", { limit, after });
|
|
345
|
-
const response = await fetch(url, {
|
|
346
|
-
headers: {
|
|
347
|
-
...this.headers,
|
|
348
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
349
|
-
}
|
|
350
|
-
});
|
|
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 });
|
|
351
187
|
if (!response.ok) {
|
|
352
|
-
throw new Error(`Failed to fetch ${
|
|
188
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos: ${response.statusText}`);
|
|
353
189
|
}
|
|
354
190
|
const data = await response.json();
|
|
355
191
|
return data;
|
|
@@ -359,26 +195,22 @@ var Git = class extends Base2 {
|
|
|
359
195
|
* @param repoName - The name of the repository.
|
|
360
196
|
* @param limit - Maximum number of pull requests to retrieve.
|
|
361
197
|
* @param after - Cursor for pagination.
|
|
362
|
-
* @param
|
|
198
|
+
* @param include_raw - Whether to include raw response data.
|
|
363
199
|
* @returns A promise that resolves to the fetch response.
|
|
364
200
|
* @throws If repoName is not provided.
|
|
365
201
|
*/
|
|
366
|
-
async pulls(
|
|
202
|
+
async pulls(repoName, { limit = 100, after, include_raw = false }) {
|
|
367
203
|
if (!repoName) {
|
|
368
204
|
throw new Error("repoName is required to fetch pulls.");
|
|
369
205
|
}
|
|
370
206
|
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/pulls`, {
|
|
371
207
|
limit,
|
|
372
|
-
after
|
|
373
|
-
|
|
374
|
-
const response = await fetch(url, {
|
|
375
|
-
headers: {
|
|
376
|
-
...this.headers,
|
|
377
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
378
|
-
}
|
|
208
|
+
after,
|
|
209
|
+
include_raw
|
|
379
210
|
});
|
|
211
|
+
const response = await fetch(url, { headers: this.headers });
|
|
380
212
|
if (!response.ok) {
|
|
381
|
-
throw new Error(`Failed to fetch ${
|
|
213
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/pulls: ${response.statusText}`);
|
|
382
214
|
}
|
|
383
215
|
const data = await response.json();
|
|
384
216
|
return data;
|
|
@@ -388,26 +220,22 @@ var Git = class extends Base2 {
|
|
|
388
220
|
* @param repoName - The name of the repository.
|
|
389
221
|
* @param limit - Maximum number of tags to retrieve.
|
|
390
222
|
* @param after - Cursor for pagination.
|
|
391
|
-
* @param
|
|
223
|
+
* @param include_raw - Whether to include raw response data.
|
|
392
224
|
* @returns A promise that resolves to the fetch response.
|
|
393
225
|
* @throws If repoName is not provided.
|
|
394
226
|
*/
|
|
395
|
-
async tags(
|
|
227
|
+
async tags(repoName, { limit = 100, after, include_raw = false }) {
|
|
396
228
|
if (!repoName) {
|
|
397
229
|
throw new Error("repoName is required to fetch tags.");
|
|
398
230
|
}
|
|
399
231
|
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/tags`, {
|
|
400
232
|
limit,
|
|
401
|
-
after
|
|
402
|
-
|
|
403
|
-
const response = await fetch(url, {
|
|
404
|
-
headers: {
|
|
405
|
-
...this.headers,
|
|
406
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
407
|
-
}
|
|
233
|
+
after,
|
|
234
|
+
include_raw
|
|
408
235
|
});
|
|
236
|
+
const response = await fetch(url, { headers: this.headers });
|
|
409
237
|
if (!response.ok) {
|
|
410
|
-
throw new Error(`Failed to fetch ${
|
|
238
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/tags: ${response.statusText}`);
|
|
411
239
|
}
|
|
412
240
|
const data = await response.json();
|
|
413
241
|
return data;
|
|
@@ -417,26 +245,22 @@ var Git = class extends Base2 {
|
|
|
417
245
|
* @param repoName - The name of the repository.
|
|
418
246
|
* @param limit - Maximum number of releases to retrieve.
|
|
419
247
|
* @param after - Cursor for pagination.
|
|
420
|
-
* @param
|
|
248
|
+
* @param include_raw - Whether to include raw response data.
|
|
421
249
|
* @returns A promise that resolves to the fetch response.
|
|
422
250
|
* @throws If repoName is not provided.
|
|
423
251
|
*/
|
|
424
|
-
async releases(
|
|
252
|
+
async releases(repoName, { limit = 100, after, include_raw = false }) {
|
|
425
253
|
if (!repoName) {
|
|
426
254
|
throw new Error("repoName is required to fetch releases.");
|
|
427
255
|
}
|
|
428
256
|
const url = this.buildUrl(`repos/${encodeURIComponent(repoName)}/releases`, {
|
|
429
257
|
limit,
|
|
430
|
-
after
|
|
431
|
-
|
|
432
|
-
const response = await fetch(url, {
|
|
433
|
-
headers: {
|
|
434
|
-
...this.headers,
|
|
435
|
-
"BU-Include-Raw": includeRaw ? "true" : "false"
|
|
436
|
-
}
|
|
258
|
+
after,
|
|
259
|
+
include_raw
|
|
437
260
|
});
|
|
261
|
+
const response = await fetch(url, { headers: this.headers });
|
|
438
262
|
if (!response.ok) {
|
|
439
|
-
throw new Error(`Failed to fetch ${
|
|
263
|
+
throw new Error(`Failed to fetch ${this.namespace}/repos/${repoName}/releases: ${response.statusText}`);
|
|
440
264
|
}
|
|
441
265
|
const data = await response.json();
|
|
442
266
|
return data;
|
|
@@ -444,7 +268,7 @@ var Git = class extends Base2 {
|
|
|
444
268
|
};
|
|
445
269
|
|
|
446
270
|
// src/unify/pm.ts
|
|
447
|
-
var PM = class extends
|
|
271
|
+
var PM = class extends Base {
|
|
448
272
|
constructor() {
|
|
449
273
|
super(...arguments);
|
|
450
274
|
this.namespace = "pm";
|
|
@@ -453,29 +277,317 @@ var PM = class extends Base2 {
|
|
|
453
277
|
* Fetch issues
|
|
454
278
|
* @param limit - Maximum number of issues to retrieve.
|
|
455
279
|
* @param after - Cursor for pagination.
|
|
456
|
-
* @param
|
|
280
|
+
* @param include_raw - Whether to include raw response data.
|
|
457
281
|
* @returns A promise that resolves to the fetch response.
|
|
458
282
|
*/
|
|
459
|
-
async issues({ limit = 100, after,
|
|
460
|
-
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);
|
|
405
|
+
const response = await fetch(url, {
|
|
406
|
+
method: "GET",
|
|
407
|
+
headers: this.headers
|
|
408
|
+
});
|
|
409
|
+
if (!response.ok) {
|
|
410
|
+
throw new Error(`Failed to retrieve ${this.namespace}: ${response.statusText}`);
|
|
411
|
+
}
|
|
412
|
+
const data = await response.json();
|
|
413
|
+
return data;
|
|
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);
|
|
461
430
|
const response = await fetch(url, {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
431
|
+
method: "PATCH",
|
|
432
|
+
headers: this.headers,
|
|
433
|
+
body: JSON.stringify(body)
|
|
466
434
|
});
|
|
467
435
|
if (!response.ok) {
|
|
468
|
-
throw new Error(`Failed to
|
|
436
|
+
throw new Error(`Failed to update ${this.namespace}: ${response.statusText}`);
|
|
469
437
|
}
|
|
470
438
|
const data = await response.json();
|
|
471
439
|
return data;
|
|
472
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
|
+
}
|
|
473
585
|
};
|
|
474
586
|
|
|
475
587
|
// src/index.ts
|
|
476
588
|
var BundleUp = class {
|
|
477
589
|
constructor(apiKey) {
|
|
478
|
-
if (
|
|
590
|
+
if (isEmpty(apiKey)) {
|
|
479
591
|
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
480
592
|
}
|
|
481
593
|
this.apiKey = apiKey;
|
|
@@ -504,7 +616,7 @@ var BundleUp = class {
|
|
|
504
616
|
* @returns A Proxy instance.
|
|
505
617
|
*/
|
|
506
618
|
proxy(connectionId) {
|
|
507
|
-
if (
|
|
619
|
+
if (isEmpty(connectionId)) {
|
|
508
620
|
throw new Error("Connection ID is required to create a Proxy instance.");
|
|
509
621
|
}
|
|
510
622
|
return new Proxy(this.apiKey, connectionId);
|
|
@@ -515,14 +627,10 @@ var BundleUp = class {
|
|
|
515
627
|
* @returns An object containing Unify methods.
|
|
516
628
|
*/
|
|
517
629
|
unify(connectionId) {
|
|
518
|
-
if (
|
|
630
|
+
if (isEmpty(connectionId)) {
|
|
519
631
|
throw new Error("Connection ID is required to create a Unify instance.");
|
|
520
632
|
}
|
|
521
|
-
return
|
|
522
|
-
chat: new Chat(this.apiKey, connectionId),
|
|
523
|
-
git: new Git(this.apiKey, connectionId),
|
|
524
|
-
pm: new PM(this.apiKey, connectionId)
|
|
525
|
-
};
|
|
633
|
+
return new Unify(this.apiKey, connectionId);
|
|
526
634
|
}
|
|
527
635
|
};
|
|
528
636
|
export {
|