@bundleup/sdk 0.0.1 → 0.0.3
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.d.mts +29 -17
- package/dist/index.d.ts +29 -17
- package/dist/index.js +139 -53
- package/dist/index.mjs +139 -53
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare abstract class Base<T> {
|
|
2
|
+
private apiKey;
|
|
2
3
|
protected abstract path: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
protected version: string;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private version;
|
|
6
6
|
constructor(apiKey: string);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private get apiUrl();
|
|
8
|
+
private get headers();
|
|
9
9
|
list<K extends Record<string, any>>(params?: K): Promise<T[]>;
|
|
10
10
|
create<K extends Record<string, any>>(body: K): Promise<T>;
|
|
11
11
|
retrieve(id: string): Promise<T>;
|
|
@@ -50,26 +50,38 @@ declare class Webhooks extends Base<Webhook> {
|
|
|
50
50
|
protected path: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
declare class
|
|
53
|
+
declare class Request {
|
|
54
54
|
private apiKey;
|
|
55
55
|
private connectionId;
|
|
56
|
+
private baseUrl;
|
|
57
|
+
private get headers();
|
|
56
58
|
constructor(apiKey: string, connectionId: string);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
private buildUrl;
|
|
60
|
+
get(path: string, searchParams?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
61
|
+
post(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
62
|
+
put(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
63
|
+
patch(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
64
|
+
delete(path: string, headers?: Record<string, string>): Promise<Response>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type ChatMessageRequest = {
|
|
68
|
+
channelId: string;
|
|
69
|
+
content: string;
|
|
70
|
+
};
|
|
71
|
+
declare class Chat extends Request {
|
|
72
|
+
message({ channelId, content }: ChatMessageRequest): Promise<Response>;
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
declare class BundleUp {
|
|
67
76
|
private apiKey;
|
|
68
77
|
constructor(apiKey: string);
|
|
69
|
-
connections(): Connections;
|
|
70
|
-
integrations(): Integrations;
|
|
71
|
-
webhooks(): Webhooks;
|
|
72
|
-
|
|
78
|
+
get connections(): Connections;
|
|
79
|
+
get integrations(): Integrations;
|
|
80
|
+
get webhooks(): Webhooks;
|
|
81
|
+
connect(connectionId: string): {
|
|
82
|
+
req: Request;
|
|
83
|
+
chat: Chat;
|
|
84
|
+
};
|
|
73
85
|
}
|
|
74
86
|
|
|
75
87
|
export { BundleUp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare abstract class Base<T> {
|
|
2
|
+
private apiKey;
|
|
2
3
|
protected abstract path: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
protected version: string;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private version;
|
|
6
6
|
constructor(apiKey: string);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private get apiUrl();
|
|
8
|
+
private get headers();
|
|
9
9
|
list<K extends Record<string, any>>(params?: K): Promise<T[]>;
|
|
10
10
|
create<K extends Record<string, any>>(body: K): Promise<T>;
|
|
11
11
|
retrieve(id: string): Promise<T>;
|
|
@@ -50,26 +50,38 @@ declare class Webhooks extends Base<Webhook> {
|
|
|
50
50
|
protected path: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
declare class
|
|
53
|
+
declare class Request {
|
|
54
54
|
private apiKey;
|
|
55
55
|
private connectionId;
|
|
56
|
+
private baseUrl;
|
|
57
|
+
private get headers();
|
|
56
58
|
constructor(apiKey: string, connectionId: string);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
private buildUrl;
|
|
60
|
+
get(path: string, searchParams?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
61
|
+
post(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
62
|
+
put(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
63
|
+
patch(path: string, body?: Record<string, any>, headers?: Record<string, string>): Promise<Response>;
|
|
64
|
+
delete(path: string, headers?: Record<string, string>): Promise<Response>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type ChatMessageRequest = {
|
|
68
|
+
channelId: string;
|
|
69
|
+
content: string;
|
|
70
|
+
};
|
|
71
|
+
declare class Chat extends Request {
|
|
72
|
+
message({ channelId, content }: ChatMessageRequest): Promise<Response>;
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
declare class BundleUp {
|
|
67
76
|
private apiKey;
|
|
68
77
|
constructor(apiKey: string);
|
|
69
|
-
connections(): Connections;
|
|
70
|
-
integrations(): Integrations;
|
|
71
|
-
webhooks(): Webhooks;
|
|
72
|
-
|
|
78
|
+
get connections(): Connections;
|
|
79
|
+
get integrations(): Integrations;
|
|
80
|
+
get webhooks(): Webhooks;
|
|
81
|
+
connect(connectionId: string): {
|
|
82
|
+
req: Request;
|
|
83
|
+
chat: Chat;
|
|
84
|
+
};
|
|
73
85
|
}
|
|
74
86
|
|
|
75
87
|
export { BundleUp };
|
package/dist/index.js
CHANGED
|
@@ -24,12 +24,17 @@ __export(src_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
|
+
// src/utils.ts
|
|
28
|
+
function isObject(value) {
|
|
29
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
// src/base.ts
|
|
28
33
|
var Base = class {
|
|
29
34
|
constructor(apiKey) {
|
|
35
|
+
this.apiKey = apiKey;
|
|
30
36
|
this.baseUrl = "https://api.bundleup.io";
|
|
31
37
|
this.version = "v1";
|
|
32
|
-
this.apiKey = apiKey;
|
|
33
38
|
}
|
|
34
39
|
get apiUrl() {
|
|
35
40
|
return `${this.baseUrl}/${this.version}`;
|
|
@@ -41,6 +46,9 @@ var Base = class {
|
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
48
|
async list(params = {}) {
|
|
49
|
+
if (!isObject(params)) {
|
|
50
|
+
throw new Error("List parameters must be an object.");
|
|
51
|
+
}
|
|
44
52
|
const response = await fetch(`${this.apiUrl}${this.path}`, {
|
|
45
53
|
method: "GET",
|
|
46
54
|
headers: this.headers,
|
|
@@ -55,6 +63,9 @@ var Base = class {
|
|
|
55
63
|
return data;
|
|
56
64
|
}
|
|
57
65
|
async create(body) {
|
|
66
|
+
if (!isObject(body)) {
|
|
67
|
+
throw new Error("Request body must be an object.");
|
|
68
|
+
}
|
|
58
69
|
const response = await fetch(`${this.apiUrl}${this.path}`, {
|
|
59
70
|
method: "POST",
|
|
60
71
|
headers: this.headers,
|
|
@@ -67,35 +78,53 @@ var Base = class {
|
|
|
67
78
|
return data;
|
|
68
79
|
}
|
|
69
80
|
async retrieve(id) {
|
|
81
|
+
if (!id) {
|
|
82
|
+
throw new Error("ID is required to retrieve a resource.");
|
|
83
|
+
}
|
|
70
84
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
71
85
|
method: "GET",
|
|
72
86
|
headers: this.headers
|
|
73
87
|
});
|
|
74
88
|
if (!response.ok) {
|
|
75
|
-
throw new Error(
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Failed to retrieve ${this.path}/${id}: ${response.statusText}`
|
|
91
|
+
);
|
|
76
92
|
}
|
|
77
93
|
const data = await response.json();
|
|
78
94
|
return data;
|
|
79
95
|
}
|
|
80
96
|
async update(id, body) {
|
|
97
|
+
if (!id) {
|
|
98
|
+
throw new Error("ID is required to update a resource.");
|
|
99
|
+
}
|
|
100
|
+
if (!isObject(body)) {
|
|
101
|
+
throw new Error("Request body must be an object.");
|
|
102
|
+
}
|
|
81
103
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
82
104
|
method: "PATCH",
|
|
83
105
|
headers: this.headers,
|
|
84
106
|
body: JSON.stringify(body)
|
|
85
107
|
});
|
|
86
108
|
if (!response.ok) {
|
|
87
|
-
throw new Error(
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Failed to update ${this.path}/${id}: ${response.statusText}`
|
|
111
|
+
);
|
|
88
112
|
}
|
|
89
113
|
const data = await response.json();
|
|
90
114
|
return data;
|
|
91
115
|
}
|
|
92
116
|
async del(id) {
|
|
117
|
+
if (!id) {
|
|
118
|
+
throw new Error("ID is required to delete a resource.");
|
|
119
|
+
}
|
|
93
120
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
94
121
|
method: "DELETE",
|
|
95
122
|
headers: this.headers
|
|
96
123
|
});
|
|
97
124
|
if (!response.ok) {
|
|
98
|
-
throw new Error(
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Failed to delete ${this.path}/${id}: ${response.statusText}`
|
|
127
|
+
);
|
|
99
128
|
}
|
|
100
129
|
}
|
|
101
130
|
};
|
|
@@ -125,13 +154,11 @@ var Webhooks = class extends Base {
|
|
|
125
154
|
};
|
|
126
155
|
|
|
127
156
|
// src/request.ts
|
|
128
|
-
var
|
|
157
|
+
var Request = class {
|
|
129
158
|
constructor(apiKey, connectionId) {
|
|
130
159
|
this.apiKey = apiKey;
|
|
131
160
|
this.connectionId = connectionId;
|
|
132
|
-
|
|
133
|
-
get baseUrl() {
|
|
134
|
-
return "https://req.bundleup.io";
|
|
161
|
+
this.baseUrl = "https://api.bundleup.com/v1";
|
|
135
162
|
}
|
|
136
163
|
get headers() {
|
|
137
164
|
return {
|
|
@@ -140,85 +167,144 @@ var BURequest = class {
|
|
|
140
167
|
"BU-Connection-Id": this.connectionId
|
|
141
168
|
};
|
|
142
169
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
170
|
+
buildUrl(path, searchParams = {}) {
|
|
171
|
+
if (!path) {
|
|
172
|
+
throw new Error("Path is required to build URL.");
|
|
173
|
+
}
|
|
174
|
+
if (!isObject(searchParams)) {
|
|
175
|
+
throw new Error("URL search params must be an object.");
|
|
176
|
+
}
|
|
177
|
+
if (!path.startsWith("/")) {
|
|
178
|
+
path = `/${path}`;
|
|
179
|
+
}
|
|
180
|
+
const url = new URL(path, this.baseUrl);
|
|
181
|
+
url.search = new URLSearchParams(searchParams).toString();
|
|
182
|
+
return url;
|
|
183
|
+
}
|
|
184
|
+
get(path, searchParams = {}, headers = {}) {
|
|
185
|
+
if (!path) {
|
|
186
|
+
throw new Error("Path is required for GET request.");
|
|
187
|
+
}
|
|
188
|
+
if (!isObject(headers)) {
|
|
189
|
+
throw new Error("Headers must be an object.");
|
|
190
|
+
}
|
|
191
|
+
if (!isObject(searchParams)) {
|
|
192
|
+
throw new Error("URL search params must be an object.");
|
|
193
|
+
}
|
|
194
|
+
const url = this.buildUrl(path, searchParams);
|
|
195
|
+
return fetch(url, {
|
|
147
196
|
method: "GET",
|
|
148
|
-
headers: this.headers
|
|
197
|
+
headers: { ...this.headers, ...headers }
|
|
149
198
|
});
|
|
150
|
-
if (!response.ok) {
|
|
151
|
-
throw new Error(`Failed to fetch ${path}: ${response.statusText}`);
|
|
152
|
-
}
|
|
153
|
-
return response.json();
|
|
154
199
|
}
|
|
155
|
-
|
|
156
|
-
|
|
200
|
+
post(path, body = {}, headers = {}) {
|
|
201
|
+
if (!path) {
|
|
202
|
+
throw new Error("Path is required for POST request.");
|
|
203
|
+
}
|
|
204
|
+
if (!isObject(headers)) {
|
|
205
|
+
throw new Error("Headers must be an object.");
|
|
206
|
+
}
|
|
207
|
+
if (!isObject(body)) {
|
|
208
|
+
throw new Error("Request body must be an object.");
|
|
209
|
+
}
|
|
210
|
+
const url = this.buildUrl(path);
|
|
211
|
+
return fetch(url, {
|
|
157
212
|
method: "POST",
|
|
158
|
-
headers: {
|
|
159
|
-
"Content-Type": "application/json",
|
|
160
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
161
|
-
},
|
|
213
|
+
headers: { ...this.headers, ...headers },
|
|
162
214
|
body: JSON.stringify(body)
|
|
163
215
|
});
|
|
164
|
-
if (!response.ok) {
|
|
165
|
-
throw new Error(`Failed to post to ${path}: ${response.statusText}`);
|
|
166
|
-
}
|
|
167
|
-
return response.json();
|
|
168
216
|
}
|
|
169
|
-
|
|
170
|
-
|
|
217
|
+
put(path, body = {}, headers = {}) {
|
|
218
|
+
if (!path) {
|
|
219
|
+
throw new Error("Path is required for PUT request.");
|
|
220
|
+
}
|
|
221
|
+
if (!isObject(headers)) {
|
|
222
|
+
throw new Error("Headers must be an object.");
|
|
223
|
+
}
|
|
224
|
+
if (!isObject(body)) {
|
|
225
|
+
throw new Error("Request body must be an object.");
|
|
226
|
+
}
|
|
227
|
+
const url = this.buildUrl(path);
|
|
228
|
+
return fetch(url, {
|
|
171
229
|
method: "PUT",
|
|
172
|
-
headers: this.headers,
|
|
230
|
+
headers: { ...this.headers, ...headers },
|
|
173
231
|
body: JSON.stringify(body)
|
|
174
232
|
});
|
|
175
|
-
if (!response.ok) {
|
|
176
|
-
throw new Error(`Failed to put to ${path}: ${response.statusText}`);
|
|
177
|
-
}
|
|
178
|
-
return response.json();
|
|
179
233
|
}
|
|
180
|
-
|
|
181
|
-
|
|
234
|
+
patch(path, body = {}, headers = {}) {
|
|
235
|
+
if (!path) {
|
|
236
|
+
throw new Error("Path is required for PATCH request.");
|
|
237
|
+
}
|
|
238
|
+
if (!isObject(headers)) {
|
|
239
|
+
throw new Error("Headers must be an object.");
|
|
240
|
+
}
|
|
241
|
+
if (!isObject(body)) {
|
|
242
|
+
throw new Error("Request body must be an object.");
|
|
243
|
+
}
|
|
244
|
+
const url = this.buildUrl(path);
|
|
245
|
+
return fetch(url, {
|
|
182
246
|
method: "PATCH",
|
|
183
|
-
headers: this.headers,
|
|
247
|
+
headers: { ...this.headers, ...headers },
|
|
184
248
|
body: JSON.stringify(body)
|
|
185
249
|
});
|
|
186
|
-
if (!response.ok) {
|
|
187
|
-
throw new Error(`Failed to patch ${path}: ${response.statusText}`);
|
|
188
|
-
}
|
|
189
|
-
return response.json();
|
|
190
250
|
}
|
|
191
|
-
|
|
192
|
-
|
|
251
|
+
delete(path, headers = {}) {
|
|
252
|
+
if (!path) {
|
|
253
|
+
throw new Error("Path is required for DELETE request.");
|
|
254
|
+
}
|
|
255
|
+
if (!isObject(headers)) {
|
|
256
|
+
throw new Error("Headers must be an object.");
|
|
257
|
+
}
|
|
258
|
+
const url = this.buildUrl(path);
|
|
259
|
+
return fetch(url, {
|
|
193
260
|
method: "DELETE",
|
|
194
|
-
headers: this.headers
|
|
261
|
+
headers: { ...this.headers, ...headers }
|
|
195
262
|
});
|
|
196
|
-
|
|
197
|
-
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// src/methods/chat.ts
|
|
267
|
+
var Chat = class extends Request {
|
|
268
|
+
message({ channelId, content }) {
|
|
269
|
+
if (!channelId) {
|
|
270
|
+
throw new Error("Channel ID is required to send a chat message.");
|
|
271
|
+
}
|
|
272
|
+
if (!content) {
|
|
273
|
+
throw new Error("Content is required to send a chat message.");
|
|
198
274
|
}
|
|
199
|
-
return
|
|
275
|
+
return this.post(
|
|
276
|
+
"/",
|
|
277
|
+
{ channelId, content },
|
|
278
|
+
{ "BU-Method": "chat.message" }
|
|
279
|
+
);
|
|
200
280
|
}
|
|
201
281
|
};
|
|
202
282
|
|
|
203
283
|
// src/index.ts
|
|
204
284
|
var BundleUp = class {
|
|
205
285
|
constructor(apiKey) {
|
|
286
|
+
if (!apiKey) {
|
|
287
|
+
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
288
|
+
}
|
|
206
289
|
this.apiKey = apiKey;
|
|
207
290
|
}
|
|
208
|
-
connections() {
|
|
291
|
+
get connections() {
|
|
209
292
|
return new Connections(this.apiKey);
|
|
210
293
|
}
|
|
211
|
-
integrations() {
|
|
294
|
+
get integrations() {
|
|
212
295
|
return new Integrations(this.apiKey);
|
|
213
296
|
}
|
|
214
|
-
webhooks() {
|
|
297
|
+
get webhooks() {
|
|
215
298
|
return new Webhooks(this.apiKey);
|
|
216
299
|
}
|
|
217
|
-
|
|
300
|
+
connect(connectionId) {
|
|
218
301
|
if (!connectionId) {
|
|
219
|
-
throw new Error("Connection ID is required to create a
|
|
302
|
+
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
220
303
|
}
|
|
221
|
-
return
|
|
304
|
+
return {
|
|
305
|
+
req: new Request(this.apiKey, connectionId),
|
|
306
|
+
chat: new Chat(this.apiKey, connectionId)
|
|
307
|
+
};
|
|
222
308
|
}
|
|
223
309
|
};
|
|
224
310
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function isObject(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
// src/base.ts
|
|
2
7
|
var Base = class {
|
|
3
8
|
constructor(apiKey) {
|
|
9
|
+
this.apiKey = apiKey;
|
|
4
10
|
this.baseUrl = "https://api.bundleup.io";
|
|
5
11
|
this.version = "v1";
|
|
6
|
-
this.apiKey = apiKey;
|
|
7
12
|
}
|
|
8
13
|
get apiUrl() {
|
|
9
14
|
return `${this.baseUrl}/${this.version}`;
|
|
@@ -15,6 +20,9 @@ var Base = class {
|
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
22
|
async list(params = {}) {
|
|
23
|
+
if (!isObject(params)) {
|
|
24
|
+
throw new Error("List parameters must be an object.");
|
|
25
|
+
}
|
|
18
26
|
const response = await fetch(`${this.apiUrl}${this.path}`, {
|
|
19
27
|
method: "GET",
|
|
20
28
|
headers: this.headers,
|
|
@@ -29,6 +37,9 @@ var Base = class {
|
|
|
29
37
|
return data;
|
|
30
38
|
}
|
|
31
39
|
async create(body) {
|
|
40
|
+
if (!isObject(body)) {
|
|
41
|
+
throw new Error("Request body must be an object.");
|
|
42
|
+
}
|
|
32
43
|
const response = await fetch(`${this.apiUrl}${this.path}`, {
|
|
33
44
|
method: "POST",
|
|
34
45
|
headers: this.headers,
|
|
@@ -41,35 +52,53 @@ var Base = class {
|
|
|
41
52
|
return data;
|
|
42
53
|
}
|
|
43
54
|
async retrieve(id) {
|
|
55
|
+
if (!id) {
|
|
56
|
+
throw new Error("ID is required to retrieve a resource.");
|
|
57
|
+
}
|
|
44
58
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
45
59
|
method: "GET",
|
|
46
60
|
headers: this.headers
|
|
47
61
|
});
|
|
48
62
|
if (!response.ok) {
|
|
49
|
-
throw new Error(
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Failed to retrieve ${this.path}/${id}: ${response.statusText}`
|
|
65
|
+
);
|
|
50
66
|
}
|
|
51
67
|
const data = await response.json();
|
|
52
68
|
return data;
|
|
53
69
|
}
|
|
54
70
|
async update(id, body) {
|
|
71
|
+
if (!id) {
|
|
72
|
+
throw new Error("ID is required to update a resource.");
|
|
73
|
+
}
|
|
74
|
+
if (!isObject(body)) {
|
|
75
|
+
throw new Error("Request body must be an object.");
|
|
76
|
+
}
|
|
55
77
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
56
78
|
method: "PATCH",
|
|
57
79
|
headers: this.headers,
|
|
58
80
|
body: JSON.stringify(body)
|
|
59
81
|
});
|
|
60
82
|
if (!response.ok) {
|
|
61
|
-
throw new Error(
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Failed to update ${this.path}/${id}: ${response.statusText}`
|
|
85
|
+
);
|
|
62
86
|
}
|
|
63
87
|
const data = await response.json();
|
|
64
88
|
return data;
|
|
65
89
|
}
|
|
66
90
|
async del(id) {
|
|
91
|
+
if (!id) {
|
|
92
|
+
throw new Error("ID is required to delete a resource.");
|
|
93
|
+
}
|
|
67
94
|
const response = await fetch(`${this.apiUrl}${this.path}/${id}`, {
|
|
68
95
|
method: "DELETE",
|
|
69
96
|
headers: this.headers
|
|
70
97
|
});
|
|
71
98
|
if (!response.ok) {
|
|
72
|
-
throw new Error(
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Failed to delete ${this.path}/${id}: ${response.statusText}`
|
|
101
|
+
);
|
|
73
102
|
}
|
|
74
103
|
}
|
|
75
104
|
};
|
|
@@ -99,13 +128,11 @@ var Webhooks = class extends Base {
|
|
|
99
128
|
};
|
|
100
129
|
|
|
101
130
|
// src/request.ts
|
|
102
|
-
var
|
|
131
|
+
var Request = class {
|
|
103
132
|
constructor(apiKey, connectionId) {
|
|
104
133
|
this.apiKey = apiKey;
|
|
105
134
|
this.connectionId = connectionId;
|
|
106
|
-
|
|
107
|
-
get baseUrl() {
|
|
108
|
-
return "https://req.bundleup.io";
|
|
135
|
+
this.baseUrl = "https://api.bundleup.com/v1";
|
|
109
136
|
}
|
|
110
137
|
get headers() {
|
|
111
138
|
return {
|
|
@@ -114,85 +141,144 @@ var BURequest = class {
|
|
|
114
141
|
"BU-Connection-Id": this.connectionId
|
|
115
142
|
};
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
144
|
+
buildUrl(path, searchParams = {}) {
|
|
145
|
+
if (!path) {
|
|
146
|
+
throw new Error("Path is required to build URL.");
|
|
147
|
+
}
|
|
148
|
+
if (!isObject(searchParams)) {
|
|
149
|
+
throw new Error("URL search params must be an object.");
|
|
150
|
+
}
|
|
151
|
+
if (!path.startsWith("/")) {
|
|
152
|
+
path = `/${path}`;
|
|
153
|
+
}
|
|
154
|
+
const url = new URL(path, this.baseUrl);
|
|
155
|
+
url.search = new URLSearchParams(searchParams).toString();
|
|
156
|
+
return url;
|
|
157
|
+
}
|
|
158
|
+
get(path, searchParams = {}, headers = {}) {
|
|
159
|
+
if (!path) {
|
|
160
|
+
throw new Error("Path is required for GET request.");
|
|
161
|
+
}
|
|
162
|
+
if (!isObject(headers)) {
|
|
163
|
+
throw new Error("Headers must be an object.");
|
|
164
|
+
}
|
|
165
|
+
if (!isObject(searchParams)) {
|
|
166
|
+
throw new Error("URL search params must be an object.");
|
|
167
|
+
}
|
|
168
|
+
const url = this.buildUrl(path, searchParams);
|
|
169
|
+
return fetch(url, {
|
|
121
170
|
method: "GET",
|
|
122
|
-
headers: this.headers
|
|
171
|
+
headers: { ...this.headers, ...headers }
|
|
123
172
|
});
|
|
124
|
-
if (!response.ok) {
|
|
125
|
-
throw new Error(`Failed to fetch ${path}: ${response.statusText}`);
|
|
126
|
-
}
|
|
127
|
-
return response.json();
|
|
128
173
|
}
|
|
129
|
-
|
|
130
|
-
|
|
174
|
+
post(path, body = {}, headers = {}) {
|
|
175
|
+
if (!path) {
|
|
176
|
+
throw new Error("Path is required for POST request.");
|
|
177
|
+
}
|
|
178
|
+
if (!isObject(headers)) {
|
|
179
|
+
throw new Error("Headers must be an object.");
|
|
180
|
+
}
|
|
181
|
+
if (!isObject(body)) {
|
|
182
|
+
throw new Error("Request body must be an object.");
|
|
183
|
+
}
|
|
184
|
+
const url = this.buildUrl(path);
|
|
185
|
+
return fetch(url, {
|
|
131
186
|
method: "POST",
|
|
132
|
-
headers: {
|
|
133
|
-
"Content-Type": "application/json",
|
|
134
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
135
|
-
},
|
|
187
|
+
headers: { ...this.headers, ...headers },
|
|
136
188
|
body: JSON.stringify(body)
|
|
137
189
|
});
|
|
138
|
-
if (!response.ok) {
|
|
139
|
-
throw new Error(`Failed to post to ${path}: ${response.statusText}`);
|
|
140
|
-
}
|
|
141
|
-
return response.json();
|
|
142
190
|
}
|
|
143
|
-
|
|
144
|
-
|
|
191
|
+
put(path, body = {}, headers = {}) {
|
|
192
|
+
if (!path) {
|
|
193
|
+
throw new Error("Path is required for PUT request.");
|
|
194
|
+
}
|
|
195
|
+
if (!isObject(headers)) {
|
|
196
|
+
throw new Error("Headers must be an object.");
|
|
197
|
+
}
|
|
198
|
+
if (!isObject(body)) {
|
|
199
|
+
throw new Error("Request body must be an object.");
|
|
200
|
+
}
|
|
201
|
+
const url = this.buildUrl(path);
|
|
202
|
+
return fetch(url, {
|
|
145
203
|
method: "PUT",
|
|
146
|
-
headers: this.headers,
|
|
204
|
+
headers: { ...this.headers, ...headers },
|
|
147
205
|
body: JSON.stringify(body)
|
|
148
206
|
});
|
|
149
|
-
if (!response.ok) {
|
|
150
|
-
throw new Error(`Failed to put to ${path}: ${response.statusText}`);
|
|
151
|
-
}
|
|
152
|
-
return response.json();
|
|
153
207
|
}
|
|
154
|
-
|
|
155
|
-
|
|
208
|
+
patch(path, body = {}, headers = {}) {
|
|
209
|
+
if (!path) {
|
|
210
|
+
throw new Error("Path is required for PATCH request.");
|
|
211
|
+
}
|
|
212
|
+
if (!isObject(headers)) {
|
|
213
|
+
throw new Error("Headers must be an object.");
|
|
214
|
+
}
|
|
215
|
+
if (!isObject(body)) {
|
|
216
|
+
throw new Error("Request body must be an object.");
|
|
217
|
+
}
|
|
218
|
+
const url = this.buildUrl(path);
|
|
219
|
+
return fetch(url, {
|
|
156
220
|
method: "PATCH",
|
|
157
|
-
headers: this.headers,
|
|
221
|
+
headers: { ...this.headers, ...headers },
|
|
158
222
|
body: JSON.stringify(body)
|
|
159
223
|
});
|
|
160
|
-
if (!response.ok) {
|
|
161
|
-
throw new Error(`Failed to patch ${path}: ${response.statusText}`);
|
|
162
|
-
}
|
|
163
|
-
return response.json();
|
|
164
224
|
}
|
|
165
|
-
|
|
166
|
-
|
|
225
|
+
delete(path, headers = {}) {
|
|
226
|
+
if (!path) {
|
|
227
|
+
throw new Error("Path is required for DELETE request.");
|
|
228
|
+
}
|
|
229
|
+
if (!isObject(headers)) {
|
|
230
|
+
throw new Error("Headers must be an object.");
|
|
231
|
+
}
|
|
232
|
+
const url = this.buildUrl(path);
|
|
233
|
+
return fetch(url, {
|
|
167
234
|
method: "DELETE",
|
|
168
|
-
headers: this.headers
|
|
235
|
+
headers: { ...this.headers, ...headers }
|
|
169
236
|
});
|
|
170
|
-
|
|
171
|
-
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// src/methods/chat.ts
|
|
241
|
+
var Chat = class extends Request {
|
|
242
|
+
message({ channelId, content }) {
|
|
243
|
+
if (!channelId) {
|
|
244
|
+
throw new Error("Channel ID is required to send a chat message.");
|
|
245
|
+
}
|
|
246
|
+
if (!content) {
|
|
247
|
+
throw new Error("Content is required to send a chat message.");
|
|
172
248
|
}
|
|
173
|
-
return
|
|
249
|
+
return this.post(
|
|
250
|
+
"/",
|
|
251
|
+
{ channelId, content },
|
|
252
|
+
{ "BU-Method": "chat.message" }
|
|
253
|
+
);
|
|
174
254
|
}
|
|
175
255
|
};
|
|
176
256
|
|
|
177
257
|
// src/index.ts
|
|
178
258
|
var BundleUp = class {
|
|
179
259
|
constructor(apiKey) {
|
|
260
|
+
if (!apiKey) {
|
|
261
|
+
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
262
|
+
}
|
|
180
263
|
this.apiKey = apiKey;
|
|
181
264
|
}
|
|
182
|
-
connections() {
|
|
265
|
+
get connections() {
|
|
183
266
|
return new Connections(this.apiKey);
|
|
184
267
|
}
|
|
185
|
-
integrations() {
|
|
268
|
+
get integrations() {
|
|
186
269
|
return new Integrations(this.apiKey);
|
|
187
270
|
}
|
|
188
|
-
webhooks() {
|
|
271
|
+
get webhooks() {
|
|
189
272
|
return new Webhooks(this.apiKey);
|
|
190
273
|
}
|
|
191
|
-
|
|
274
|
+
connect(connectionId) {
|
|
192
275
|
if (!connectionId) {
|
|
193
|
-
throw new Error("Connection ID is required to create a
|
|
276
|
+
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
194
277
|
}
|
|
195
|
-
return
|
|
278
|
+
return {
|
|
279
|
+
req: new Request(this.apiKey, connectionId),
|
|
280
|
+
chat: new Chat(this.apiKey, connectionId)
|
|
281
|
+
};
|
|
196
282
|
}
|
|
197
283
|
};
|
|
198
284
|
export {
|