@bundleup/sdk 0.0.6 → 0.0.8

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 CHANGED
@@ -4,12 +4,43 @@ declare abstract class Base<T> {
4
4
  private baseUrl;
5
5
  private version;
6
6
  constructor(apiKey: string);
7
- private get apiUrl();
8
- private get headers();
7
+ protected get apiUrl(): string;
8
+ protected get headers(): Record<string, string>;
9
+ /**
10
+ * List resources with optional query parameters.
11
+ * @param params - Query parameters for filtering the list.
12
+ * @returns A promise that resolves to an array of resources.
13
+ * @throws If params is not an object or if the fetch request fails.
14
+ */
9
15
  list<K extends Record<string, any>>(params?: K): Promise<T[]>;
16
+ /**
17
+ * Create a new resource.
18
+ * @param body - The request body containing resource details.
19
+ * @returns A promise that resolves to the created resource.
20
+ * @throws If body is not an object or if the fetch request fails.
21
+ */
10
22
  create<K extends Record<string, any>>(body: K): Promise<T>;
23
+ /**
24
+ * Retrieve a specific resource by ID.
25
+ * @param id - The ID of the resource to retrieve.
26
+ * @returns A promise that resolves to the retrieved resource.
27
+ * @throws If id is not provided or if the fetch request fails.
28
+ */
11
29
  retrieve(id: string): Promise<T>;
30
+ /**
31
+ * Update a specific resource by ID.
32
+ * @param id - The ID of the resource to update.
33
+ * @param body - The request body containing updated resource details.
34
+ * @returns A promise that resolves to the updated resource.
35
+ * @throws If id is not provided, if body is not an object, or if the fetch request fails.
36
+ */
12
37
  update<K extends Record<string, any>>(id: string, body: K): Promise<T>;
38
+ /**
39
+ * Delete a specific resource by ID.
40
+ * @param id - The ID of the resource to delete.
41
+ * @returns A promise that resolves when the resource is deleted.
42
+ * @throws If id is not provided or if the fetch request fails.
43
+ */
13
44
  del(id: string): Promise<void>;
14
45
  }
15
46
 
@@ -28,10 +59,10 @@ declare class Connections extends Base<Connection> {
28
59
  }
29
60
 
30
61
  interface Integration {
31
- id: true;
32
- identifier: true;
33
- createdAt: true;
34
- updatedAt: true;
62
+ id: string;
63
+ identifier: string;
64
+ createdAt: Date;
65
+ updatedAt: Date;
35
66
  }
36
67
  declare class Integrations extends Base<Integration> {
37
68
  protected path: string;
@@ -64,6 +95,29 @@ declare class Request {
64
95
  delete(path: string, headers?: Record<string, string>): Promise<Response>;
65
96
  }
66
97
 
98
+ interface SessionCreateRequest {
99
+ integrationId: string;
100
+ externalId?: string;
101
+ metadata?: Record<string, any>;
102
+ }
103
+ interface SessionCreateResponse {
104
+ expires_in: number;
105
+ token: string;
106
+ externalId?: string;
107
+ }
108
+ declare class Sessions {
109
+ private apiKey;
110
+ constructor(apiKey: string);
111
+ private get headers();
112
+ /**
113
+ * Create a new session.
114
+ * @param params - The session creation parameters.
115
+ * @returns A promise that resolves to the created session details.
116
+ * @throws If the fetch request fails.
117
+ */
118
+ create(params: SessionCreateRequest): Promise<SessionCreateResponse>;
119
+ }
120
+
67
121
  type ChatMessageRequest = {
68
122
  channelId: string;
69
123
  content: string;
@@ -71,6 +125,14 @@ type ChatMessageRequest = {
71
125
  declare class Chat {
72
126
  private req;
73
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
+ */
74
136
  message({ channelId, content }: ChatMessageRequest): Promise<Response>;
75
137
  }
76
138
 
@@ -80,6 +142,7 @@ declare class BundleUp {
80
142
  get connections(): Connections;
81
143
  get integrations(): Integrations;
82
144
  get webhooks(): Webhooks;
145
+ get sessions(): Sessions;
83
146
  connect(connectionId: string): {
84
147
  req: Request;
85
148
  chat: Chat;
package/dist/index.d.ts CHANGED
@@ -4,12 +4,43 @@ declare abstract class Base<T> {
4
4
  private baseUrl;
5
5
  private version;
6
6
  constructor(apiKey: string);
7
- private get apiUrl();
8
- private get headers();
7
+ protected get apiUrl(): string;
8
+ protected get headers(): Record<string, string>;
9
+ /**
10
+ * List resources with optional query parameters.
11
+ * @param params - Query parameters for filtering the list.
12
+ * @returns A promise that resolves to an array of resources.
13
+ * @throws If params is not an object or if the fetch request fails.
14
+ */
9
15
  list<K extends Record<string, any>>(params?: K): Promise<T[]>;
16
+ /**
17
+ * Create a new resource.
18
+ * @param body - The request body containing resource details.
19
+ * @returns A promise that resolves to the created resource.
20
+ * @throws If body is not an object or if the fetch request fails.
21
+ */
10
22
  create<K extends Record<string, any>>(body: K): Promise<T>;
23
+ /**
24
+ * Retrieve a specific resource by ID.
25
+ * @param id - The ID of the resource to retrieve.
26
+ * @returns A promise that resolves to the retrieved resource.
27
+ * @throws If id is not provided or if the fetch request fails.
28
+ */
11
29
  retrieve(id: string): Promise<T>;
30
+ /**
31
+ * Update a specific resource by ID.
32
+ * @param id - The ID of the resource to update.
33
+ * @param body - The request body containing updated resource details.
34
+ * @returns A promise that resolves to the updated resource.
35
+ * @throws If id is not provided, if body is not an object, or if the fetch request fails.
36
+ */
12
37
  update<K extends Record<string, any>>(id: string, body: K): Promise<T>;
38
+ /**
39
+ * Delete a specific resource by ID.
40
+ * @param id - The ID of the resource to delete.
41
+ * @returns A promise that resolves when the resource is deleted.
42
+ * @throws If id is not provided or if the fetch request fails.
43
+ */
13
44
  del(id: string): Promise<void>;
14
45
  }
15
46
 
@@ -28,10 +59,10 @@ declare class Connections extends Base<Connection> {
28
59
  }
29
60
 
30
61
  interface Integration {
31
- id: true;
32
- identifier: true;
33
- createdAt: true;
34
- updatedAt: true;
62
+ id: string;
63
+ identifier: string;
64
+ createdAt: Date;
65
+ updatedAt: Date;
35
66
  }
36
67
  declare class Integrations extends Base<Integration> {
37
68
  protected path: string;
@@ -64,6 +95,29 @@ declare class Request {
64
95
  delete(path: string, headers?: Record<string, string>): Promise<Response>;
65
96
  }
66
97
 
98
+ interface SessionCreateRequest {
99
+ integrationId: string;
100
+ externalId?: string;
101
+ metadata?: Record<string, any>;
102
+ }
103
+ interface SessionCreateResponse {
104
+ expires_in: number;
105
+ token: string;
106
+ externalId?: string;
107
+ }
108
+ declare class Sessions {
109
+ private apiKey;
110
+ constructor(apiKey: string);
111
+ private get headers();
112
+ /**
113
+ * Create a new session.
114
+ * @param params - The session creation parameters.
115
+ * @returns A promise that resolves to the created session details.
116
+ * @throws If the fetch request fails.
117
+ */
118
+ create(params: SessionCreateRequest): Promise<SessionCreateResponse>;
119
+ }
120
+
67
121
  type ChatMessageRequest = {
68
122
  channelId: string;
69
123
  content: string;
@@ -71,6 +125,14 @@ type ChatMessageRequest = {
71
125
  declare class Chat {
72
126
  private req;
73
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
+ */
74
136
  message({ channelId, content }: ChatMessageRequest): Promise<Response>;
75
137
  }
76
138
 
@@ -80,6 +142,7 @@ declare class BundleUp {
80
142
  get connections(): Connections;
81
143
  get integrations(): Integrations;
82
144
  get webhooks(): Webhooks;
145
+ get sessions(): Sessions;
83
146
  connect(connectionId: string): {
84
147
  req: Request;
85
148
  chat: Chat;
package/dist/index.js CHANGED
@@ -45,6 +45,12 @@ var Base = class {
45
45
  Authorization: `Bearer ${this.apiKey}`
46
46
  };
47
47
  }
48
+ /**
49
+ * List resources with optional query parameters.
50
+ * @param params - Query parameters for filtering the list.
51
+ * @returns A promise that resolves to an array of resources.
52
+ * @throws If params is not an object or if the fetch request fails.
53
+ */
48
54
  async list(params = {}) {
49
55
  if (!isObject(params)) {
50
56
  throw new Error("List parameters must be an object.");
@@ -62,6 +68,12 @@ var Base = class {
62
68
  const data = await response.json();
63
69
  return data;
64
70
  }
71
+ /**
72
+ * Create a new resource.
73
+ * @param body - The request body containing resource details.
74
+ * @returns A promise that resolves to the created resource.
75
+ * @throws If body is not an object or if the fetch request fails.
76
+ */
65
77
  async create(body) {
66
78
  if (!isObject(body)) {
67
79
  throw new Error("Request body must be an object.");
@@ -77,6 +89,12 @@ var Base = class {
77
89
  const data = await response.json();
78
90
  return data;
79
91
  }
92
+ /**
93
+ * Retrieve a specific resource by ID.
94
+ * @param id - The ID of the resource to retrieve.
95
+ * @returns A promise that resolves to the retrieved resource.
96
+ * @throws If id is not provided or if the fetch request fails.
97
+ */
80
98
  async retrieve(id) {
81
99
  if (!id) {
82
100
  throw new Error("ID is required to retrieve a resource.");
@@ -93,6 +111,13 @@ var Base = class {
93
111
  const data = await response.json();
94
112
  return data;
95
113
  }
114
+ /**
115
+ * Update a specific resource by ID.
116
+ * @param id - The ID of the resource to update.
117
+ * @param body - The request body containing updated resource details.
118
+ * @returns A promise that resolves to the updated resource.
119
+ * @throws If id is not provided, if body is not an object, or if the fetch request fails.
120
+ */
96
121
  async update(id, body) {
97
122
  if (!id) {
98
123
  throw new Error("ID is required to update a resource.");
@@ -113,6 +138,12 @@ var Base = class {
113
138
  const data = await response.json();
114
139
  return data;
115
140
  }
141
+ /**
142
+ * Delete a specific resource by ID.
143
+ * @param id - The ID of the resource to delete.
144
+ * @returns A promise that resolves when the resource is deleted.
145
+ * @throws If id is not provided or if the fetch request fails.
146
+ */
116
147
  async del(id) {
117
148
  if (!id) {
118
149
  throw new Error("ID is required to delete a resource.");
@@ -263,11 +294,50 @@ var Request = class {
263
294
  }
264
295
  };
265
296
 
297
+ // src/session.ts
298
+ var Sessions = class {
299
+ constructor(apiKey) {
300
+ this.apiKey = apiKey;
301
+ }
302
+ get headers() {
303
+ return {
304
+ "Content-Type": "application/json",
305
+ Authorization: `Bearer ${this.apiKey}`
306
+ };
307
+ }
308
+ /**
309
+ * Create a new session.
310
+ * @param params - The session creation parameters.
311
+ * @returns A promise that resolves to the created session details.
312
+ * @throws If the fetch request fails.
313
+ */
314
+ async create(params) {
315
+ const response = await fetch("https://api.bundleup.io/v1/sessions", {
316
+ method: "POST",
317
+ headers: this.headers,
318
+ body: JSON.stringify(params)
319
+ });
320
+ if (!response.ok) {
321
+ throw new Error("Failed to create session");
322
+ }
323
+ const data = await response.json();
324
+ return data;
325
+ }
326
+ };
327
+
266
328
  // src/methods/chat.ts
267
329
  var Chat = class {
268
330
  constructor(apiKey, connectionId) {
269
331
  this.req = new Request(apiKey, connectionId);
270
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
+ */
271
341
  message({ channelId, content }) {
272
342
  if (!channelId) {
273
343
  throw new Error("Channel ID is required to send a chat message.");
@@ -300,6 +370,9 @@ var BundleUp = class {
300
370
  get webhooks() {
301
371
  return new Webhooks(this.apiKey);
302
372
  }
373
+ get sessions() {
374
+ return new Sessions(this.apiKey);
375
+ }
303
376
  connect(connectionId) {
304
377
  if (!connectionId) {
305
378
  throw new Error("Connection ID is required to create a Fetch instance.");
package/dist/index.mjs CHANGED
@@ -19,6 +19,12 @@ var Base = class {
19
19
  Authorization: `Bearer ${this.apiKey}`
20
20
  };
21
21
  }
22
+ /**
23
+ * List resources with optional query parameters.
24
+ * @param params - Query parameters for filtering the list.
25
+ * @returns A promise that resolves to an array of resources.
26
+ * @throws If params is not an object or if the fetch request fails.
27
+ */
22
28
  async list(params = {}) {
23
29
  if (!isObject(params)) {
24
30
  throw new Error("List parameters must be an object.");
@@ -36,6 +42,12 @@ var Base = class {
36
42
  const data = await response.json();
37
43
  return data;
38
44
  }
45
+ /**
46
+ * Create a new resource.
47
+ * @param body - The request body containing resource details.
48
+ * @returns A promise that resolves to the created resource.
49
+ * @throws If body is not an object or if the fetch request fails.
50
+ */
39
51
  async create(body) {
40
52
  if (!isObject(body)) {
41
53
  throw new Error("Request body must be an object.");
@@ -51,6 +63,12 @@ var Base = class {
51
63
  const data = await response.json();
52
64
  return data;
53
65
  }
66
+ /**
67
+ * Retrieve a specific resource by ID.
68
+ * @param id - The ID of the resource to retrieve.
69
+ * @returns A promise that resolves to the retrieved resource.
70
+ * @throws If id is not provided or if the fetch request fails.
71
+ */
54
72
  async retrieve(id) {
55
73
  if (!id) {
56
74
  throw new Error("ID is required to retrieve a resource.");
@@ -67,6 +85,13 @@ var Base = class {
67
85
  const data = await response.json();
68
86
  return data;
69
87
  }
88
+ /**
89
+ * Update a specific resource by ID.
90
+ * @param id - The ID of the resource to update.
91
+ * @param body - The request body containing updated resource details.
92
+ * @returns A promise that resolves to the updated resource.
93
+ * @throws If id is not provided, if body is not an object, or if the fetch request fails.
94
+ */
70
95
  async update(id, body) {
71
96
  if (!id) {
72
97
  throw new Error("ID is required to update a resource.");
@@ -87,6 +112,12 @@ var Base = class {
87
112
  const data = await response.json();
88
113
  return data;
89
114
  }
115
+ /**
116
+ * Delete a specific resource by ID.
117
+ * @param id - The ID of the resource to delete.
118
+ * @returns A promise that resolves when the resource is deleted.
119
+ * @throws If id is not provided or if the fetch request fails.
120
+ */
90
121
  async del(id) {
91
122
  if (!id) {
92
123
  throw new Error("ID is required to delete a resource.");
@@ -237,11 +268,50 @@ var Request = class {
237
268
  }
238
269
  };
239
270
 
271
+ // src/session.ts
272
+ var Sessions = class {
273
+ constructor(apiKey) {
274
+ this.apiKey = apiKey;
275
+ }
276
+ get headers() {
277
+ return {
278
+ "Content-Type": "application/json",
279
+ Authorization: `Bearer ${this.apiKey}`
280
+ };
281
+ }
282
+ /**
283
+ * Create a new session.
284
+ * @param params - The session creation parameters.
285
+ * @returns A promise that resolves to the created session details.
286
+ * @throws If the fetch request fails.
287
+ */
288
+ async create(params) {
289
+ const response = await fetch("https://api.bundleup.io/v1/sessions", {
290
+ method: "POST",
291
+ headers: this.headers,
292
+ body: JSON.stringify(params)
293
+ });
294
+ if (!response.ok) {
295
+ throw new Error("Failed to create session");
296
+ }
297
+ const data = await response.json();
298
+ return data;
299
+ }
300
+ };
301
+
240
302
  // src/methods/chat.ts
241
303
  var Chat = class {
242
304
  constructor(apiKey, connectionId) {
243
305
  this.req = new Request(apiKey, connectionId);
244
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
+ */
245
315
  message({ channelId, content }) {
246
316
  if (!channelId) {
247
317
  throw new Error("Channel ID is required to send a chat message.");
@@ -274,6 +344,9 @@ var BundleUp = class {
274
344
  get webhooks() {
275
345
  return new Webhooks(this.apiKey);
276
346
  }
347
+ get sessions() {
348
+ return new Sessions(this.apiKey);
349
+ }
277
350
  connect(connectionId) {
278
351
  if (!connectionId) {
279
352
  throw new Error("Connection ID is required to create a Fetch instance.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bundleup/sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "SDK package for BundleUp",
5
5
  "exports": {
6
6
  ".": {