@bundleup/sdk 0.0.10 → 0.0.11
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 +26 -30
- package/dist/index.d.ts +26 -30
- package/dist/index.js +56 -58
- package/dist/index.mjs +56 -58
- package/package.json +6 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
declare abstract class Base<T> {
|
|
2
2
|
private apiKey;
|
|
3
|
-
protected abstract
|
|
3
|
+
protected abstract namespace: string;
|
|
4
4
|
private baseUrl;
|
|
5
5
|
private version;
|
|
6
6
|
constructor(apiKey: string);
|
|
7
|
-
|
|
7
|
+
private buildUrl;
|
|
8
8
|
protected get headers(): Record<string, string>;
|
|
9
9
|
/**
|
|
10
10
|
* List resources with optional query parameters.
|
|
11
|
-
* @param
|
|
11
|
+
* @param searchParams - Query parameters for filtering the list.
|
|
12
12
|
* @returns A promise that resolves to an array of resources.
|
|
13
13
|
* @throws If params is not an object or if the fetch request fails.
|
|
14
14
|
*/
|
|
15
|
-
list<K extends Record<string, any>>(
|
|
15
|
+
list<K extends Record<string, any>>(searchParams?: K): Promise<T[]>;
|
|
16
16
|
/**
|
|
17
17
|
* Create a new resource.
|
|
18
18
|
* @param body - The request body containing resource details.
|
|
@@ -55,7 +55,7 @@ interface Connection {
|
|
|
55
55
|
updatedAt: Date;
|
|
56
56
|
}
|
|
57
57
|
declare class Connections extends Base<Connection> {
|
|
58
|
-
protected
|
|
58
|
+
protected namespace: string;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
interface Integration {
|
|
@@ -65,7 +65,7 @@ interface Integration {
|
|
|
65
65
|
updatedAt: Date;
|
|
66
66
|
}
|
|
67
67
|
declare class Integrations extends Base<Integration> {
|
|
68
|
-
protected
|
|
68
|
+
protected namespace: string;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
interface Webhook {
|
|
@@ -78,10 +78,10 @@ interface Webhook {
|
|
|
78
78
|
lastTriggeredAt?: Date;
|
|
79
79
|
}
|
|
80
80
|
declare class Webhooks extends Base<Webhook> {
|
|
81
|
-
protected
|
|
81
|
+
protected namespace: string;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
declare class
|
|
84
|
+
declare class Proxy {
|
|
85
85
|
private apiKey;
|
|
86
86
|
private connectionId;
|
|
87
87
|
private baseUrl;
|
|
@@ -118,35 +118,31 @@ declare class Sessions {
|
|
|
118
118
|
create(params: SessionCreateRequest): Promise<SessionCreateResponse>;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
type ChatMessageRequest = {
|
|
122
|
-
channelId: string;
|
|
123
|
-
content: string;
|
|
124
|
-
};
|
|
125
|
-
declare class Chat {
|
|
126
|
-
private req;
|
|
127
|
-
constructor(apiKey: string, connectionId: string);
|
|
128
|
-
/**
|
|
129
|
-
* Send a chat message to a specific channel.
|
|
130
|
-
* @param params - The parameters for sending a chat message.
|
|
131
|
-
* @param params.channelId - The ID of the channel to send the message to.
|
|
132
|
-
* @param params.content - The content of the chat message.
|
|
133
|
-
* @returns The response from the API.
|
|
134
|
-
* @throws If channelId or content is missing.
|
|
135
|
-
*/
|
|
136
|
-
message({ channelId, content }: ChatMessageRequest): Promise<Response>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
121
|
declare class BundleUp {
|
|
140
122
|
private apiKey;
|
|
141
123
|
constructor(apiKey: string);
|
|
124
|
+
/**
|
|
125
|
+
* Access the Connections resource.
|
|
126
|
+
*/
|
|
142
127
|
get connections(): Connections;
|
|
128
|
+
/**
|
|
129
|
+
* Access the Integrations resource.
|
|
130
|
+
*/
|
|
143
131
|
get integrations(): Integrations;
|
|
132
|
+
/**
|
|
133
|
+
* Access the Webhooks resource.
|
|
134
|
+
*/
|
|
144
135
|
get webhooks(): Webhooks;
|
|
136
|
+
/**
|
|
137
|
+
* Access the Sessions resource.
|
|
138
|
+
*/
|
|
145
139
|
get sessions(): Sessions;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Create a Proxy instance for a specific connection.
|
|
142
|
+
* @param connectionId - The ID of the connection.
|
|
143
|
+
* @returns A Proxy instance.
|
|
144
|
+
*/
|
|
145
|
+
proxy(connectionId: string): Proxy;
|
|
150
146
|
}
|
|
151
147
|
|
|
152
148
|
export { BundleUp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
declare abstract class Base<T> {
|
|
2
2
|
private apiKey;
|
|
3
|
-
protected abstract
|
|
3
|
+
protected abstract namespace: string;
|
|
4
4
|
private baseUrl;
|
|
5
5
|
private version;
|
|
6
6
|
constructor(apiKey: string);
|
|
7
|
-
|
|
7
|
+
private buildUrl;
|
|
8
8
|
protected get headers(): Record<string, string>;
|
|
9
9
|
/**
|
|
10
10
|
* List resources with optional query parameters.
|
|
11
|
-
* @param
|
|
11
|
+
* @param searchParams - Query parameters for filtering the list.
|
|
12
12
|
* @returns A promise that resolves to an array of resources.
|
|
13
13
|
* @throws If params is not an object or if the fetch request fails.
|
|
14
14
|
*/
|
|
15
|
-
list<K extends Record<string, any>>(
|
|
15
|
+
list<K extends Record<string, any>>(searchParams?: K): Promise<T[]>;
|
|
16
16
|
/**
|
|
17
17
|
* Create a new resource.
|
|
18
18
|
* @param body - The request body containing resource details.
|
|
@@ -55,7 +55,7 @@ interface Connection {
|
|
|
55
55
|
updatedAt: Date;
|
|
56
56
|
}
|
|
57
57
|
declare class Connections extends Base<Connection> {
|
|
58
|
-
protected
|
|
58
|
+
protected namespace: string;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
interface Integration {
|
|
@@ -65,7 +65,7 @@ interface Integration {
|
|
|
65
65
|
updatedAt: Date;
|
|
66
66
|
}
|
|
67
67
|
declare class Integrations extends Base<Integration> {
|
|
68
|
-
protected
|
|
68
|
+
protected namespace: string;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
interface Webhook {
|
|
@@ -78,10 +78,10 @@ interface Webhook {
|
|
|
78
78
|
lastTriggeredAt?: Date;
|
|
79
79
|
}
|
|
80
80
|
declare class Webhooks extends Base<Webhook> {
|
|
81
|
-
protected
|
|
81
|
+
protected namespace: string;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
declare class
|
|
84
|
+
declare class Proxy {
|
|
85
85
|
private apiKey;
|
|
86
86
|
private connectionId;
|
|
87
87
|
private baseUrl;
|
|
@@ -118,35 +118,31 @@ declare class Sessions {
|
|
|
118
118
|
create(params: SessionCreateRequest): Promise<SessionCreateResponse>;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
type ChatMessageRequest = {
|
|
122
|
-
channelId: string;
|
|
123
|
-
content: string;
|
|
124
|
-
};
|
|
125
|
-
declare class Chat {
|
|
126
|
-
private req;
|
|
127
|
-
constructor(apiKey: string, connectionId: string);
|
|
128
|
-
/**
|
|
129
|
-
* Send a chat message to a specific channel.
|
|
130
|
-
* @param params - The parameters for sending a chat message.
|
|
131
|
-
* @param params.channelId - The ID of the channel to send the message to.
|
|
132
|
-
* @param params.content - The content of the chat message.
|
|
133
|
-
* @returns The response from the API.
|
|
134
|
-
* @throws If channelId or content is missing.
|
|
135
|
-
*/
|
|
136
|
-
message({ channelId, content }: ChatMessageRequest): Promise<Response>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
121
|
declare class BundleUp {
|
|
140
122
|
private apiKey;
|
|
141
123
|
constructor(apiKey: string);
|
|
124
|
+
/**
|
|
125
|
+
* Access the Connections resource.
|
|
126
|
+
*/
|
|
142
127
|
get connections(): Connections;
|
|
128
|
+
/**
|
|
129
|
+
* Access the Integrations resource.
|
|
130
|
+
*/
|
|
143
131
|
get integrations(): Integrations;
|
|
132
|
+
/**
|
|
133
|
+
* Access the Webhooks resource.
|
|
134
|
+
*/
|
|
144
135
|
get webhooks(): Webhooks;
|
|
136
|
+
/**
|
|
137
|
+
* Access the Sessions resource.
|
|
138
|
+
*/
|
|
145
139
|
get sessions(): Sessions;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Create a Proxy instance for a specific connection.
|
|
142
|
+
* @param connectionId - The ID of the connection.
|
|
143
|
+
* @returns A Proxy instance.
|
|
144
|
+
*/
|
|
145
|
+
proxy(connectionId: string): Proxy;
|
|
150
146
|
}
|
|
151
147
|
|
|
152
148
|
export { BundleUp };
|
package/dist/index.js
CHANGED
|
@@ -36,8 +36,14 @@ var Base = class {
|
|
|
36
36
|
this.baseUrl = "https://api.bundleup.io";
|
|
37
37
|
this.version = "v1";
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
const url = new URL(parts, this.baseUrl);
|
|
45
|
+
url.search = new URLSearchParams(searchParams).toString();
|
|
46
|
+
return url;
|
|
41
47
|
}
|
|
42
48
|
get headers() {
|
|
43
49
|
return {
|
|
@@ -47,23 +53,23 @@ var Base = class {
|
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* List resources with optional query parameters.
|
|
50
|
-
* @param
|
|
56
|
+
* @param searchParams - Query parameters for filtering the list.
|
|
51
57
|
* @returns A promise that resolves to an array of resources.
|
|
52
58
|
* @throws If params is not an object or if the fetch request fails.
|
|
53
59
|
*/
|
|
54
|
-
async list(
|
|
55
|
-
if (!isObject(
|
|
60
|
+
async list(searchParams = {}) {
|
|
61
|
+
if (!isObject(searchParams)) {
|
|
56
62
|
throw new Error("List parameters must be an object.");
|
|
57
63
|
}
|
|
58
|
-
const
|
|
64
|
+
const url = this.buildUrl(null, searchParams);
|
|
65
|
+
const response = await fetch(url, {
|
|
59
66
|
method: "GET",
|
|
60
|
-
headers: this.headers
|
|
61
|
-
body: JSON.stringify({
|
|
62
|
-
...params
|
|
63
|
-
})
|
|
67
|
+
headers: this.headers
|
|
64
68
|
});
|
|
65
69
|
if (!response.ok) {
|
|
66
|
-
throw new Error(
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
72
|
+
);
|
|
67
73
|
}
|
|
68
74
|
const data = await response.json();
|
|
69
75
|
return data;
|
|
@@ -78,13 +84,16 @@ var Base = class {
|
|
|
78
84
|
if (!isObject(body)) {
|
|
79
85
|
throw new Error("Request body must be an object.");
|
|
80
86
|
}
|
|
81
|
-
const
|
|
87
|
+
const url = this.buildUrl(null);
|
|
88
|
+
const response = await fetch(url, {
|
|
82
89
|
method: "POST",
|
|
83
90
|
headers: this.headers,
|
|
84
91
|
body: JSON.stringify(body)
|
|
85
92
|
});
|
|
86
93
|
if (!response.ok) {
|
|
87
|
-
throw new Error(
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Failed to create ${url.toString()}: ${response.statusText}`
|
|
96
|
+
);
|
|
88
97
|
}
|
|
89
98
|
const data = await response.json();
|
|
90
99
|
return data;
|
|
@@ -99,13 +108,14 @@ var Base = class {
|
|
|
99
108
|
if (!id) {
|
|
100
109
|
throw new Error("ID is required to retrieve a resource.");
|
|
101
110
|
}
|
|
102
|
-
const
|
|
111
|
+
const url = this.buildUrl(id);
|
|
112
|
+
const response = await fetch(url, {
|
|
103
113
|
method: "GET",
|
|
104
114
|
headers: this.headers
|
|
105
115
|
});
|
|
106
116
|
if (!response.ok) {
|
|
107
117
|
throw new Error(
|
|
108
|
-
`Failed to retrieve ${
|
|
118
|
+
`Failed to retrieve ${url.toString()}: ${response.statusText}`
|
|
109
119
|
);
|
|
110
120
|
}
|
|
111
121
|
const data = await response.json();
|
|
@@ -125,14 +135,15 @@ var Base = class {
|
|
|
125
135
|
if (!isObject(body)) {
|
|
126
136
|
throw new Error("Request body must be an object.");
|
|
127
137
|
}
|
|
128
|
-
const
|
|
138
|
+
const url = this.buildUrl(id);
|
|
139
|
+
const response = await fetch(url, {
|
|
129
140
|
method: "PATCH",
|
|
130
141
|
headers: this.headers,
|
|
131
142
|
body: JSON.stringify(body)
|
|
132
143
|
});
|
|
133
144
|
if (!response.ok) {
|
|
134
145
|
throw new Error(
|
|
135
|
-
`Failed to update ${
|
|
146
|
+
`Failed to update ${url.toString()}: ${response.statusText}`
|
|
136
147
|
);
|
|
137
148
|
}
|
|
138
149
|
const data = await response.json();
|
|
@@ -148,13 +159,14 @@ var Base = class {
|
|
|
148
159
|
if (!id) {
|
|
149
160
|
throw new Error("ID is required to delete a resource.");
|
|
150
161
|
}
|
|
151
|
-
const
|
|
162
|
+
const url = this.buildUrl(id);
|
|
163
|
+
const response = await fetch(url, {
|
|
152
164
|
method: "DELETE",
|
|
153
165
|
headers: this.headers
|
|
154
166
|
});
|
|
155
167
|
if (!response.ok) {
|
|
156
168
|
throw new Error(
|
|
157
|
-
`Failed to delete ${
|
|
169
|
+
`Failed to delete ${url.toString()}: ${response.statusText}`
|
|
158
170
|
);
|
|
159
171
|
}
|
|
160
172
|
}
|
|
@@ -164,7 +176,7 @@ var Base = class {
|
|
|
164
176
|
var Connections = class extends Base {
|
|
165
177
|
constructor() {
|
|
166
178
|
super(...arguments);
|
|
167
|
-
this.
|
|
179
|
+
this.namespace = "connections";
|
|
168
180
|
}
|
|
169
181
|
};
|
|
170
182
|
|
|
@@ -172,7 +184,7 @@ var Connections = class extends Base {
|
|
|
172
184
|
var Integrations = class extends Base {
|
|
173
185
|
constructor() {
|
|
174
186
|
super(...arguments);
|
|
175
|
-
this.
|
|
187
|
+
this.namespace = "integrations";
|
|
176
188
|
}
|
|
177
189
|
};
|
|
178
190
|
|
|
@@ -180,16 +192,16 @@ var Integrations = class extends Base {
|
|
|
180
192
|
var Webhooks = class extends Base {
|
|
181
193
|
constructor() {
|
|
182
194
|
super(...arguments);
|
|
183
|
-
this.
|
|
195
|
+
this.namespace = "webhooks";
|
|
184
196
|
}
|
|
185
197
|
};
|
|
186
198
|
|
|
187
|
-
// src/
|
|
188
|
-
var
|
|
199
|
+
// src/proxy.ts
|
|
200
|
+
var Proxy2 = class {
|
|
189
201
|
constructor(apiKey, connectionId) {
|
|
190
202
|
this.apiKey = apiKey;
|
|
191
203
|
this.connectionId = connectionId;
|
|
192
|
-
this.baseUrl = "https://
|
|
204
|
+
this.baseUrl = "https://proxy.bundleup.io";
|
|
193
205
|
}
|
|
194
206
|
get headers() {
|
|
195
207
|
return {
|
|
@@ -325,34 +337,6 @@ var Sessions = class {
|
|
|
325
337
|
}
|
|
326
338
|
};
|
|
327
339
|
|
|
328
|
-
// src/methods/chat.ts
|
|
329
|
-
var Chat = class {
|
|
330
|
-
constructor(apiKey, connectionId) {
|
|
331
|
-
this.req = new Request(apiKey, connectionId);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Send a chat message to a specific channel.
|
|
335
|
-
* @param params - The parameters for sending a chat message.
|
|
336
|
-
* @param params.channelId - The ID of the channel to send the message to.
|
|
337
|
-
* @param params.content - The content of the chat message.
|
|
338
|
-
* @returns The response from the API.
|
|
339
|
-
* @throws If channelId or content is missing.
|
|
340
|
-
*/
|
|
341
|
-
message({ channelId, content }) {
|
|
342
|
-
if (!channelId) {
|
|
343
|
-
throw new Error("Channel ID is required to send a chat message.");
|
|
344
|
-
}
|
|
345
|
-
if (!content) {
|
|
346
|
-
throw new Error("Content is required to send a chat message.");
|
|
347
|
-
}
|
|
348
|
-
return this.req.post(
|
|
349
|
-
"/",
|
|
350
|
-
{ channel_id: channelId, content },
|
|
351
|
-
{ "BU-Method": "chat.message" }
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
|
|
356
340
|
// src/index.ts
|
|
357
341
|
var BundleUp = class {
|
|
358
342
|
constructor(apiKey) {
|
|
@@ -361,26 +345,40 @@ var BundleUp = class {
|
|
|
361
345
|
}
|
|
362
346
|
this.apiKey = apiKey;
|
|
363
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Access the Connections resource.
|
|
350
|
+
*/
|
|
364
351
|
get connections() {
|
|
365
352
|
return new Connections(this.apiKey);
|
|
366
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Access the Integrations resource.
|
|
356
|
+
*/
|
|
367
357
|
get integrations() {
|
|
368
358
|
return new Integrations(this.apiKey);
|
|
369
359
|
}
|
|
360
|
+
/**
|
|
361
|
+
* Access the Webhooks resource.
|
|
362
|
+
*/
|
|
370
363
|
get webhooks() {
|
|
371
364
|
return new Webhooks(this.apiKey);
|
|
372
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Access the Sessions resource.
|
|
368
|
+
*/
|
|
373
369
|
get sessions() {
|
|
374
370
|
return new Sessions(this.apiKey);
|
|
375
371
|
}
|
|
376
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Create a Proxy instance for a specific connection.
|
|
374
|
+
* @param connectionId - The ID of the connection.
|
|
375
|
+
* @returns A Proxy instance.
|
|
376
|
+
*/
|
|
377
|
+
proxy(connectionId) {
|
|
377
378
|
if (!connectionId) {
|
|
378
379
|
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
379
380
|
}
|
|
380
|
-
return
|
|
381
|
-
req: new Request(this.apiKey, connectionId),
|
|
382
|
-
chat: new Chat(this.apiKey, connectionId)
|
|
383
|
-
};
|
|
381
|
+
return new Proxy2(this.apiKey, connectionId);
|
|
384
382
|
}
|
|
385
383
|
};
|
|
386
384
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -10,8 +10,14 @@ var Base = class {
|
|
|
10
10
|
this.baseUrl = "https://api.bundleup.io";
|
|
11
11
|
this.version = "v1";
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
const url = new URL(parts, this.baseUrl);
|
|
19
|
+
url.search = new URLSearchParams(searchParams).toString();
|
|
20
|
+
return url;
|
|
15
21
|
}
|
|
16
22
|
get headers() {
|
|
17
23
|
return {
|
|
@@ -21,23 +27,23 @@ var Base = class {
|
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* List resources with optional query parameters.
|
|
24
|
-
* @param
|
|
30
|
+
* @param searchParams - Query parameters for filtering the list.
|
|
25
31
|
* @returns A promise that resolves to an array of resources.
|
|
26
32
|
* @throws If params is not an object or if the fetch request fails.
|
|
27
33
|
*/
|
|
28
|
-
async list(
|
|
29
|
-
if (!isObject(
|
|
34
|
+
async list(searchParams = {}) {
|
|
35
|
+
if (!isObject(searchParams)) {
|
|
30
36
|
throw new Error("List parameters must be an object.");
|
|
31
37
|
}
|
|
32
|
-
const
|
|
38
|
+
const url = this.buildUrl(null, searchParams);
|
|
39
|
+
const response = await fetch(url, {
|
|
33
40
|
method: "GET",
|
|
34
|
-
headers: this.headers
|
|
35
|
-
body: JSON.stringify({
|
|
36
|
-
...params
|
|
37
|
-
})
|
|
41
|
+
headers: this.headers
|
|
38
42
|
});
|
|
39
43
|
if (!response.ok) {
|
|
40
|
-
throw new Error(
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Failed to fetch ${url.toString()}: ${response.statusText}`
|
|
46
|
+
);
|
|
41
47
|
}
|
|
42
48
|
const data = await response.json();
|
|
43
49
|
return data;
|
|
@@ -52,13 +58,16 @@ var Base = class {
|
|
|
52
58
|
if (!isObject(body)) {
|
|
53
59
|
throw new Error("Request body must be an object.");
|
|
54
60
|
}
|
|
55
|
-
const
|
|
61
|
+
const url = this.buildUrl(null);
|
|
62
|
+
const response = await fetch(url, {
|
|
56
63
|
method: "POST",
|
|
57
64
|
headers: this.headers,
|
|
58
65
|
body: JSON.stringify(body)
|
|
59
66
|
});
|
|
60
67
|
if (!response.ok) {
|
|
61
|
-
throw new Error(
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Failed to create ${url.toString()}: ${response.statusText}`
|
|
70
|
+
);
|
|
62
71
|
}
|
|
63
72
|
const data = await response.json();
|
|
64
73
|
return data;
|
|
@@ -73,13 +82,14 @@ var Base = class {
|
|
|
73
82
|
if (!id) {
|
|
74
83
|
throw new Error("ID is required to retrieve a resource.");
|
|
75
84
|
}
|
|
76
|
-
const
|
|
85
|
+
const url = this.buildUrl(id);
|
|
86
|
+
const response = await fetch(url, {
|
|
77
87
|
method: "GET",
|
|
78
88
|
headers: this.headers
|
|
79
89
|
});
|
|
80
90
|
if (!response.ok) {
|
|
81
91
|
throw new Error(
|
|
82
|
-
`Failed to retrieve ${
|
|
92
|
+
`Failed to retrieve ${url.toString()}: ${response.statusText}`
|
|
83
93
|
);
|
|
84
94
|
}
|
|
85
95
|
const data = await response.json();
|
|
@@ -99,14 +109,15 @@ var Base = class {
|
|
|
99
109
|
if (!isObject(body)) {
|
|
100
110
|
throw new Error("Request body must be an object.");
|
|
101
111
|
}
|
|
102
|
-
const
|
|
112
|
+
const url = this.buildUrl(id);
|
|
113
|
+
const response = await fetch(url, {
|
|
103
114
|
method: "PATCH",
|
|
104
115
|
headers: this.headers,
|
|
105
116
|
body: JSON.stringify(body)
|
|
106
117
|
});
|
|
107
118
|
if (!response.ok) {
|
|
108
119
|
throw new Error(
|
|
109
|
-
`Failed to update ${
|
|
120
|
+
`Failed to update ${url.toString()}: ${response.statusText}`
|
|
110
121
|
);
|
|
111
122
|
}
|
|
112
123
|
const data = await response.json();
|
|
@@ -122,13 +133,14 @@ var Base = class {
|
|
|
122
133
|
if (!id) {
|
|
123
134
|
throw new Error("ID is required to delete a resource.");
|
|
124
135
|
}
|
|
125
|
-
const
|
|
136
|
+
const url = this.buildUrl(id);
|
|
137
|
+
const response = await fetch(url, {
|
|
126
138
|
method: "DELETE",
|
|
127
139
|
headers: this.headers
|
|
128
140
|
});
|
|
129
141
|
if (!response.ok) {
|
|
130
142
|
throw new Error(
|
|
131
|
-
`Failed to delete ${
|
|
143
|
+
`Failed to delete ${url.toString()}: ${response.statusText}`
|
|
132
144
|
);
|
|
133
145
|
}
|
|
134
146
|
}
|
|
@@ -138,7 +150,7 @@ var Base = class {
|
|
|
138
150
|
var Connections = class extends Base {
|
|
139
151
|
constructor() {
|
|
140
152
|
super(...arguments);
|
|
141
|
-
this.
|
|
153
|
+
this.namespace = "connections";
|
|
142
154
|
}
|
|
143
155
|
};
|
|
144
156
|
|
|
@@ -146,7 +158,7 @@ var Connections = class extends Base {
|
|
|
146
158
|
var Integrations = class extends Base {
|
|
147
159
|
constructor() {
|
|
148
160
|
super(...arguments);
|
|
149
|
-
this.
|
|
161
|
+
this.namespace = "integrations";
|
|
150
162
|
}
|
|
151
163
|
};
|
|
152
164
|
|
|
@@ -154,16 +166,16 @@ var Integrations = class extends Base {
|
|
|
154
166
|
var Webhooks = class extends Base {
|
|
155
167
|
constructor() {
|
|
156
168
|
super(...arguments);
|
|
157
|
-
this.
|
|
169
|
+
this.namespace = "webhooks";
|
|
158
170
|
}
|
|
159
171
|
};
|
|
160
172
|
|
|
161
|
-
// src/
|
|
162
|
-
var
|
|
173
|
+
// src/proxy.ts
|
|
174
|
+
var Proxy = class {
|
|
163
175
|
constructor(apiKey, connectionId) {
|
|
164
176
|
this.apiKey = apiKey;
|
|
165
177
|
this.connectionId = connectionId;
|
|
166
|
-
this.baseUrl = "https://
|
|
178
|
+
this.baseUrl = "https://proxy.bundleup.io";
|
|
167
179
|
}
|
|
168
180
|
get headers() {
|
|
169
181
|
return {
|
|
@@ -299,34 +311,6 @@ var Sessions = class {
|
|
|
299
311
|
}
|
|
300
312
|
};
|
|
301
313
|
|
|
302
|
-
// src/methods/chat.ts
|
|
303
|
-
var Chat = class {
|
|
304
|
-
constructor(apiKey, connectionId) {
|
|
305
|
-
this.req = new Request(apiKey, connectionId);
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Send a chat message to a specific channel.
|
|
309
|
-
* @param params - The parameters for sending a chat message.
|
|
310
|
-
* @param params.channelId - The ID of the channel to send the message to.
|
|
311
|
-
* @param params.content - The content of the chat message.
|
|
312
|
-
* @returns The response from the API.
|
|
313
|
-
* @throws If channelId or content is missing.
|
|
314
|
-
*/
|
|
315
|
-
message({ channelId, content }) {
|
|
316
|
-
if (!channelId) {
|
|
317
|
-
throw new Error("Channel ID is required to send a chat message.");
|
|
318
|
-
}
|
|
319
|
-
if (!content) {
|
|
320
|
-
throw new Error("Content is required to send a chat message.");
|
|
321
|
-
}
|
|
322
|
-
return this.req.post(
|
|
323
|
-
"/",
|
|
324
|
-
{ channel_id: channelId, content },
|
|
325
|
-
{ "BU-Method": "chat.message" }
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
314
|
// src/index.ts
|
|
331
315
|
var BundleUp = class {
|
|
332
316
|
constructor(apiKey) {
|
|
@@ -335,26 +319,40 @@ var BundleUp = class {
|
|
|
335
319
|
}
|
|
336
320
|
this.apiKey = apiKey;
|
|
337
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Access the Connections resource.
|
|
324
|
+
*/
|
|
338
325
|
get connections() {
|
|
339
326
|
return new Connections(this.apiKey);
|
|
340
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Access the Integrations resource.
|
|
330
|
+
*/
|
|
341
331
|
get integrations() {
|
|
342
332
|
return new Integrations(this.apiKey);
|
|
343
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Access the Webhooks resource.
|
|
336
|
+
*/
|
|
344
337
|
get webhooks() {
|
|
345
338
|
return new Webhooks(this.apiKey);
|
|
346
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Access the Sessions resource.
|
|
342
|
+
*/
|
|
347
343
|
get sessions() {
|
|
348
344
|
return new Sessions(this.apiKey);
|
|
349
345
|
}
|
|
350
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Create a Proxy instance for a specific connection.
|
|
348
|
+
* @param connectionId - The ID of the connection.
|
|
349
|
+
* @returns A Proxy instance.
|
|
350
|
+
*/
|
|
351
|
+
proxy(connectionId) {
|
|
351
352
|
if (!connectionId) {
|
|
352
353
|
throw new Error("Connection ID is required to create a Fetch instance.");
|
|
353
354
|
}
|
|
354
|
-
return
|
|
355
|
-
req: new Request(this.apiKey, connectionId),
|
|
356
|
-
chat: new Chat(this.apiKey, connectionId)
|
|
357
|
-
};
|
|
355
|
+
return new Proxy(this.apiKey, connectionId);
|
|
358
356
|
}
|
|
359
357
|
};
|
|
360
358
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bundleup/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "SDK package for BundleUp",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -17,14 +17,16 @@
|
|
|
17
17
|
"clean": "rm -rf dist"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@types/jest": "^29.5.0",
|
|
21
|
+
"jest": "^29.0.0",
|
|
22
|
+
"ts-jest": "^29.1.0",
|
|
20
23
|
"tsup": "^7.0.0",
|
|
21
24
|
"typescript": "^5.0.0",
|
|
22
|
-
"eslint": "^8.0.0"
|
|
23
|
-
"jest": "^29.0.0"
|
|
25
|
+
"eslint": "^8.0.0"
|
|
24
26
|
},
|
|
25
27
|
"files": [
|
|
26
28
|
"dist"
|
|
27
29
|
],
|
|
28
30
|
"author": "BundleUp",
|
|
29
31
|
"license": "ISC"
|
|
30
|
-
}
|
|
32
|
+
}
|