@bundleup/sdk 0.0.2 → 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 +28 -16
- package/dist/index.d.ts +28 -16
- package/dist/index.js +138 -29
- package/dist/index.mjs +138 -29
- 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>;
|
|
@@ -53,23 +53,35 @@ declare class Webhooks extends Base<Webhook> {
|
|
|
53
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>;
|
|
@@ -53,23 +53,35 @@ declare class Webhooks extends Base<Webhook> {
|
|
|
53
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
|
};
|
|
@@ -129,9 +158,7 @@ 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,62 +167,144 @@ var Request = 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
199
|
}
|
|
151
|
-
post(path, body = {}) {
|
|
152
|
-
|
|
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, {
|
|
153
212
|
method: "POST",
|
|
154
|
-
headers: this.headers,
|
|
213
|
+
headers: { ...this.headers, ...headers },
|
|
155
214
|
body: JSON.stringify(body)
|
|
156
215
|
});
|
|
157
216
|
}
|
|
158
|
-
put(path, body = {}) {
|
|
159
|
-
|
|
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, {
|
|
160
229
|
method: "PUT",
|
|
161
|
-
headers: this.headers,
|
|
230
|
+
headers: { ...this.headers, ...headers },
|
|
162
231
|
body: JSON.stringify(body)
|
|
163
232
|
});
|
|
164
233
|
}
|
|
165
|
-
patch(path, body = {}) {
|
|
166
|
-
|
|
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, {
|
|
167
246
|
method: "PATCH",
|
|
168
|
-
headers: this.headers,
|
|
247
|
+
headers: { ...this.headers, ...headers },
|
|
169
248
|
body: JSON.stringify(body)
|
|
170
249
|
});
|
|
171
250
|
}
|
|
172
|
-
delete(path) {
|
|
173
|
-
|
|
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, {
|
|
174
260
|
method: "DELETE",
|
|
175
|
-
headers: this.headers
|
|
261
|
+
headers: { ...this.headers, ...headers }
|
|
176
262
|
});
|
|
177
263
|
}
|
|
178
264
|
};
|
|
179
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.");
|
|
274
|
+
}
|
|
275
|
+
return this.post(
|
|
276
|
+
"/",
|
|
277
|
+
{ channelId, content },
|
|
278
|
+
{ "BU-Method": "chat.message" }
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
180
283
|
// src/index.ts
|
|
181
284
|
var BundleUp = class {
|
|
182
285
|
constructor(apiKey) {
|
|
286
|
+
if (!apiKey) {
|
|
287
|
+
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
288
|
+
}
|
|
183
289
|
this.apiKey = apiKey;
|
|
184
290
|
}
|
|
185
|
-
connections() {
|
|
291
|
+
get connections() {
|
|
186
292
|
return new Connections(this.apiKey);
|
|
187
293
|
}
|
|
188
|
-
integrations() {
|
|
294
|
+
get integrations() {
|
|
189
295
|
return new Integrations(this.apiKey);
|
|
190
296
|
}
|
|
191
|
-
webhooks() {
|
|
297
|
+
get webhooks() {
|
|
192
298
|
return new Webhooks(this.apiKey);
|
|
193
299
|
}
|
|
194
|
-
|
|
300
|
+
connect(connectionId) {
|
|
195
301
|
if (!connectionId) {
|
|
196
302
|
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
197
303
|
}
|
|
198
|
-
return
|
|
304
|
+
return {
|
|
305
|
+
req: new Request(this.apiKey, connectionId),
|
|
306
|
+
chat: new Chat(this.apiKey, connectionId)
|
|
307
|
+
};
|
|
199
308
|
}
|
|
200
309
|
};
|
|
201
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
|
};
|
|
@@ -103,9 +132,7 @@ 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,62 +141,144 @@ var Request = 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
173
|
}
|
|
125
|
-
post(path, body = {}) {
|
|
126
|
-
|
|
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, {
|
|
127
186
|
method: "POST",
|
|
128
|
-
headers: this.headers,
|
|
187
|
+
headers: { ...this.headers, ...headers },
|
|
129
188
|
body: JSON.stringify(body)
|
|
130
189
|
});
|
|
131
190
|
}
|
|
132
|
-
put(path, body = {}) {
|
|
133
|
-
|
|
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, {
|
|
134
203
|
method: "PUT",
|
|
135
|
-
headers: this.headers,
|
|
204
|
+
headers: { ...this.headers, ...headers },
|
|
136
205
|
body: JSON.stringify(body)
|
|
137
206
|
});
|
|
138
207
|
}
|
|
139
|
-
patch(path, body = {}) {
|
|
140
|
-
|
|
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, {
|
|
141
220
|
method: "PATCH",
|
|
142
|
-
headers: this.headers,
|
|
221
|
+
headers: { ...this.headers, ...headers },
|
|
143
222
|
body: JSON.stringify(body)
|
|
144
223
|
});
|
|
145
224
|
}
|
|
146
|
-
delete(path) {
|
|
147
|
-
|
|
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, {
|
|
148
234
|
method: "DELETE",
|
|
149
|
-
headers: this.headers
|
|
235
|
+
headers: { ...this.headers, ...headers }
|
|
150
236
|
});
|
|
151
237
|
}
|
|
152
238
|
};
|
|
153
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.");
|
|
248
|
+
}
|
|
249
|
+
return this.post(
|
|
250
|
+
"/",
|
|
251
|
+
{ channelId, content },
|
|
252
|
+
{ "BU-Method": "chat.message" }
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
154
257
|
// src/index.ts
|
|
155
258
|
var BundleUp = class {
|
|
156
259
|
constructor(apiKey) {
|
|
260
|
+
if (!apiKey) {
|
|
261
|
+
throw new Error("API key is required to initialize BundleUp SDK.");
|
|
262
|
+
}
|
|
157
263
|
this.apiKey = apiKey;
|
|
158
264
|
}
|
|
159
|
-
connections() {
|
|
265
|
+
get connections() {
|
|
160
266
|
return new Connections(this.apiKey);
|
|
161
267
|
}
|
|
162
|
-
integrations() {
|
|
268
|
+
get integrations() {
|
|
163
269
|
return new Integrations(this.apiKey);
|
|
164
270
|
}
|
|
165
|
-
webhooks() {
|
|
271
|
+
get webhooks() {
|
|
166
272
|
return new Webhooks(this.apiKey);
|
|
167
273
|
}
|
|
168
|
-
|
|
274
|
+
connect(connectionId) {
|
|
169
275
|
if (!connectionId) {
|
|
170
276
|
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
171
277
|
}
|
|
172
|
-
return
|
|
278
|
+
return {
|
|
279
|
+
req: new Request(this.apiKey, connectionId),
|
|
280
|
+
chat: new Chat(this.apiKey, connectionId)
|
|
281
|
+
};
|
|
173
282
|
}
|
|
174
283
|
};
|
|
175
284
|
export {
|