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