rocketchat-ts-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,961 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+
5
+ class RocketChatClient {
6
+ constructor(config) {
7
+ this.config = config;
8
+ this.api = axios.create({
9
+ baseURL: `${config.baseUrl}/api/v1`,
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ },
13
+ });
14
+ // Add auth interceptor
15
+ this.api.interceptors.request.use((requestConfig) => {
16
+ if (this.config.userId && this.config.authToken) {
17
+ requestConfig.headers["X-Auth-Token"] = this.config.authToken;
18
+ requestConfig.headers["X-User-Id"] = this.config.userId;
19
+ }
20
+ return requestConfig;
21
+ });
22
+ }
23
+ async login(username, password) {
24
+ var _a, _b;
25
+ try {
26
+ const credentials = {
27
+ user: username || this.config.username,
28
+ password: password || this.config.password,
29
+ };
30
+ const response = await this.api.post("/login", credentials);
31
+ if (response.data.status === "success") {
32
+ this.config.authToken = response.data.data.authToken;
33
+ this.config.userId = response.data.data.userId;
34
+ return {
35
+ success: true,
36
+ data: response.data.data,
37
+ };
38
+ }
39
+ return {
40
+ success: false,
41
+ error: "Login failed",
42
+ };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ success: false,
47
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
48
+ };
49
+ }
50
+ }
51
+ async logout() {
52
+ var _a, _b;
53
+ try {
54
+ await this.api.post("/logout");
55
+ this.config.authToken = undefined;
56
+ this.config.userId = undefined;
57
+ return { success: true };
58
+ }
59
+ catch (error) {
60
+ return {
61
+ success: false,
62
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
63
+ };
64
+ }
65
+ }
66
+ async get(endpoint, params) {
67
+ var _a, _b;
68
+ try {
69
+ const response = await this.api.get(endpoint, { params });
70
+ return {
71
+ success: true,
72
+ data: response.data,
73
+ };
74
+ }
75
+ catch (error) {
76
+ return {
77
+ success: false,
78
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
79
+ };
80
+ }
81
+ }
82
+ async post(endpoint, data) {
83
+ var _a, _b;
84
+ try {
85
+ const response = await this.api.post(endpoint, data);
86
+ return {
87
+ success: true,
88
+ data: response.data,
89
+ };
90
+ }
91
+ catch (error) {
92
+ return {
93
+ success: false,
94
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
95
+ };
96
+ }
97
+ }
98
+ async put(endpoint, data) {
99
+ var _a, _b;
100
+ try {
101
+ const response = await this.api.put(endpoint, data);
102
+ return {
103
+ success: true,
104
+ data: response.data,
105
+ };
106
+ }
107
+ catch (error) {
108
+ return {
109
+ success: false,
110
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
111
+ };
112
+ }
113
+ }
114
+ async delete(endpoint) {
115
+ var _a, _b;
116
+ try {
117
+ const response = await this.api.delete(endpoint);
118
+ return {
119
+ success: true,
120
+ data: response.data,
121
+ };
122
+ }
123
+ catch (error) {
124
+ return {
125
+ success: false,
126
+ error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message,
127
+ };
128
+ }
129
+ }
130
+ }
131
+
132
+ class ChannelResource {
133
+ constructor(client) {
134
+ this.client = client;
135
+ }
136
+ /**
137
+ * Create a new public channel
138
+ */
139
+ async create(name, members, readOnly = false) {
140
+ return this.client.post("/channels.create", {
141
+ name,
142
+ members,
143
+ readOnly,
144
+ });
145
+ }
146
+ /**
147
+ * Get channel information
148
+ */
149
+ async info(roomId, roomName) {
150
+ const params = {};
151
+ if (roomId)
152
+ params.roomId = roomId;
153
+ if (roomName)
154
+ params.roomName = roomName;
155
+ return this.client.get("/channels.info", params);
156
+ }
157
+ /**
158
+ * List all channels
159
+ */
160
+ async list(offset = 0, count = 50, sort) {
161
+ return this.client.get("/channels.list", {
162
+ offset,
163
+ count,
164
+ sort: sort ? JSON.stringify(sort) : undefined,
165
+ });
166
+ }
167
+ /**
168
+ * Join a channel
169
+ */
170
+ async join(roomId, roomName, joinCode) {
171
+ const data = {};
172
+ if (roomId)
173
+ data.roomId = roomId;
174
+ if (roomName)
175
+ data.roomName = roomName;
176
+ if (joinCode)
177
+ data.joinCode = joinCode;
178
+ return this.client.post("/channels.join", data);
179
+ }
180
+ /**
181
+ * Leave a channel
182
+ */
183
+ async leave(roomId, roomName) {
184
+ const data = {};
185
+ if (roomId)
186
+ data.roomId = roomId;
187
+ if (roomName)
188
+ data.roomName = roomName;
189
+ return this.client.post("/channels.leave", data);
190
+ }
191
+ /**
192
+ * Invite user to channel
193
+ */
194
+ async invite(roomId, userId) {
195
+ return this.client.post("/channels.invite", {
196
+ roomId,
197
+ userId,
198
+ });
199
+ }
200
+ /**
201
+ * Kick user from channel
202
+ */
203
+ async kick(roomId, userId) {
204
+ return this.client.post("/channels.kick", {
205
+ roomId,
206
+ userId,
207
+ });
208
+ }
209
+ /**
210
+ * Archive a channel
211
+ */
212
+ async archive(roomId, roomName) {
213
+ const data = {};
214
+ if (roomId)
215
+ data.roomId = roomId;
216
+ if (roomName)
217
+ data.roomName = roomName;
218
+ return this.client.post("/channels.archive", data);
219
+ }
220
+ /**
221
+ * Unarchive a channel
222
+ */
223
+ async unarchive(roomId, roomName) {
224
+ const data = {};
225
+ if (roomId)
226
+ data.roomId = roomId;
227
+ if (roomName)
228
+ data.roomName = roomName;
229
+ return this.client.post("/channels.unarchive", data);
230
+ }
231
+ /**
232
+ * Delete a channel
233
+ */
234
+ async delete(roomId, roomName) {
235
+ const data = {};
236
+ if (roomId)
237
+ data.roomId = roomId;
238
+ if (roomName)
239
+ data.roomName = roomName;
240
+ return this.client.post("/channels.delete", data);
241
+ }
242
+ /**
243
+ * Set channel topic
244
+ */
245
+ async setTopic(roomId, topic) {
246
+ return this.client.post("/channels.setTopic", {
247
+ roomId,
248
+ topic,
249
+ });
250
+ }
251
+ /**
252
+ * Set channel description
253
+ */
254
+ async setDescription(roomId, description) {
255
+ return this.client.post("/channels.setDescription", {
256
+ roomId,
257
+ description,
258
+ });
259
+ }
260
+ /**
261
+ * Rename channel
262
+ */
263
+ async rename(roomId, name) {
264
+ return this.client.post("/channels.rename", {
265
+ roomId,
266
+ name,
267
+ });
268
+ }
269
+ }
270
+
271
+ class ChatResource {
272
+ constructor(client) {
273
+ this.client = client;
274
+ }
275
+ /**
276
+ * Send a message
277
+ */
278
+ async postMessage(roomId, text, alias, emoji, avatar) {
279
+ return this.client.post("/chat.postMessage", {
280
+ roomId,
281
+ text,
282
+ alias,
283
+ emoji,
284
+ avatar,
285
+ });
286
+ }
287
+ /**
288
+ * Update a message
289
+ */
290
+ async update(roomId, msgId, text) {
291
+ return this.client.post("/chat.update", {
292
+ roomId,
293
+ msgId,
294
+ text,
295
+ });
296
+ }
297
+ /**
298
+ * Delete a message
299
+ */
300
+ async delete(roomId, msgId, asUser) {
301
+ return this.client.post("/chat.delete", {
302
+ roomId,
303
+ msgId,
304
+ asUser,
305
+ });
306
+ }
307
+ /**
308
+ * Get message
309
+ */
310
+ async getMessage(msgId) {
311
+ return this.client.get("/chat.getMessage", { msgId });
312
+ }
313
+ /**
314
+ * Pin a message
315
+ */
316
+ async pinMessage(messageId) {
317
+ return this.client.post("/chat.pinMessage", {
318
+ messageId,
319
+ });
320
+ }
321
+ /**
322
+ * Unpin a message
323
+ */
324
+ async unPinMessage(messageId) {
325
+ return this.client.post("/chat.unPinMessage", {
326
+ messageId,
327
+ });
328
+ }
329
+ /**
330
+ * Star a message
331
+ */
332
+ async starMessage(messageId) {
333
+ return this.client.post("/chat.starMessage", {
334
+ messageId,
335
+ });
336
+ }
337
+ /**
338
+ * Unstar a message
339
+ */
340
+ async unStarMessage(messageId) {
341
+ return this.client.post("/chat.unStarMessage", {
342
+ messageId,
343
+ });
344
+ }
345
+ /**
346
+ * React to a message
347
+ */
348
+ async react(messageId, emoji, shouldReact = true) {
349
+ return this.client.post("/chat.react", {
350
+ messageId,
351
+ emoji,
352
+ shouldReact,
353
+ });
354
+ }
355
+ /**
356
+ * Get pinned messages
357
+ */
358
+ async getPinnedMessages(roomId, offset = 0, count = 50) {
359
+ return this.client.get("/chat.getPinnedMessages", {
360
+ roomId,
361
+ offset,
362
+ count,
363
+ });
364
+ }
365
+ /**
366
+ * Get starred messages
367
+ */
368
+ async getStarredMessages(roomId, offset = 0, count = 50) {
369
+ return this.client.get("/chat.getStarredMessages", {
370
+ roomId,
371
+ offset,
372
+ count,
373
+ });
374
+ }
375
+ /**
376
+ * Search messages
377
+ */
378
+ async search(roomId, searchText, count = 20) {
379
+ return this.client.get("/chat.search", {
380
+ roomId,
381
+ searchText,
382
+ count,
383
+ });
384
+ }
385
+ /**
386
+ * Send typing notification
387
+ */
388
+ async sendTyping(roomId, username, typing = true) {
389
+ return this.client.post("/chat.sendTyping", {
390
+ roomId,
391
+ username,
392
+ typing,
393
+ });
394
+ }
395
+ /**
396
+ * Ignore user
397
+ */
398
+ async ignoreUser(roomId, userId, ignore = true) {
399
+ return this.client.get("/chat.ignoreUser", {
400
+ roomId,
401
+ userId,
402
+ ignore,
403
+ });
404
+ }
405
+ }
406
+
407
+ class DirectMessageResource {
408
+ constructor(client) {
409
+ this.client = client;
410
+ }
411
+ /**
412
+ * Create a direct message session
413
+ */
414
+ async create(username) {
415
+ return this.client.post("/dm.create", {
416
+ username,
417
+ });
418
+ }
419
+ /**
420
+ * Get direct message information
421
+ */
422
+ async info(roomId, username) {
423
+ const params = {};
424
+ if (roomId)
425
+ params.roomId = roomId;
426
+ if (username)
427
+ params.username = username;
428
+ return this.client.get("/dm.info", params);
429
+ }
430
+ /**
431
+ * List direct messages
432
+ */
433
+ async list(offset = 0, count = 50, sort) {
434
+ return this.client.get("/dm.list", {
435
+ offset,
436
+ count,
437
+ sort: sort ? JSON.stringify(sort) : undefined,
438
+ });
439
+ }
440
+ /**
441
+ * List everyone on the server
442
+ */
443
+ async listEveryone(offset = 0, count = 50, sort) {
444
+ return this.client.get("/dm.list.everyone", {
445
+ offset,
446
+ count,
447
+ sort: sort ? JSON.stringify(sort) : undefined,
448
+ });
449
+ }
450
+ /**
451
+ * Get direct message history
452
+ */
453
+ async history(roomId, latest, oldest, inclusive, offset = 0, count = 20) {
454
+ const params = {
455
+ roomId,
456
+ offset,
457
+ count,
458
+ };
459
+ if (latest)
460
+ params.latest = latest.toISOString();
461
+ if (oldest)
462
+ params.oldest = oldest.toISOString();
463
+ if (inclusive !== undefined)
464
+ params.inclusive = inclusive;
465
+ return this.client.get("/dm.history", params);
466
+ }
467
+ /**
468
+ * Get direct message counters
469
+ */
470
+ async counters(roomId, username) {
471
+ const params = {};
472
+ if (roomId)
473
+ params.roomId = roomId;
474
+ if (username)
475
+ params.username = username;
476
+ return this.client.get("/dm.counters", params);
477
+ }
478
+ /**
479
+ * Get direct message members
480
+ */
481
+ async members(roomId, username, offset = 0, count = 50) {
482
+ const params = {
483
+ offset,
484
+ count,
485
+ };
486
+ if (roomId)
487
+ params.roomId = roomId;
488
+ if (username)
489
+ params.username = username;
490
+ return this.client.get("/dm.members", params);
491
+ }
492
+ /**
493
+ * Get direct message messages
494
+ */
495
+ async messages(roomId, username, offset = 0, count = 20, sort) {
496
+ const params = {
497
+ offset,
498
+ count,
499
+ };
500
+ if (roomId)
501
+ params.roomId = roomId;
502
+ if (username)
503
+ params.username = username;
504
+ if (sort)
505
+ params.sort = JSON.stringify(sort);
506
+ return this.client.get("/dm.messages", params);
507
+ }
508
+ /**
509
+ * Close a direct message
510
+ */
511
+ async close(roomId, username) {
512
+ const data = {};
513
+ if (roomId)
514
+ data.roomId = roomId;
515
+ if (username)
516
+ data.username = username;
517
+ return this.client.post("/dm.close", data);
518
+ }
519
+ /**
520
+ * Hide a direct message
521
+ */
522
+ async hide(roomId, username) {
523
+ const data = {};
524
+ if (roomId)
525
+ data.roomId = roomId;
526
+ if (username)
527
+ data.username = username;
528
+ return this.client.post("/dm.hide", data);
529
+ }
530
+ /**
531
+ * Open a direct message
532
+ */
533
+ async open(roomId, username) {
534
+ const data = {};
535
+ if (roomId)
536
+ data.roomId = roomId;
537
+ if (username)
538
+ data.username = username;
539
+ return this.client.post("/dm.open", data);
540
+ }
541
+ }
542
+
543
+ class GroupResource {
544
+ constructor(client) {
545
+ this.client = client;
546
+ }
547
+ /**
548
+ * Create a new private group
549
+ */
550
+ async create(name, members, readOnly = false) {
551
+ return this.client.post("/groups.create", {
552
+ name,
553
+ members,
554
+ readOnly,
555
+ });
556
+ }
557
+ /**
558
+ * Get group information
559
+ */
560
+ async info(roomId, roomName) {
561
+ const params = {};
562
+ if (roomId)
563
+ params.roomId = roomId;
564
+ if (roomName)
565
+ params.roomName = roomName;
566
+ return this.client.get("/groups.info", params);
567
+ }
568
+ /**
569
+ * List groups
570
+ */
571
+ async list(offset = 0, count = 50, sort) {
572
+ return this.client.get("/groups.list", {
573
+ offset,
574
+ count,
575
+ sort: sort ? JSON.stringify(sort) : undefined,
576
+ });
577
+ }
578
+ /**
579
+ * List all groups
580
+ */
581
+ async listAll(offset = 0, count = 50, sort, fields) {
582
+ const params = {
583
+ offset,
584
+ count,
585
+ };
586
+ if (sort)
587
+ params.sort = JSON.stringify(sort);
588
+ if (fields)
589
+ params.fields = JSON.stringify(fields);
590
+ return this.client.get("/groups.listAll", params);
591
+ }
592
+ /**
593
+ * Invite user to group
594
+ */
595
+ async invite(roomId, userId) {
596
+ return this.client.post("/groups.invite", {
597
+ roomId,
598
+ userId,
599
+ });
600
+ }
601
+ /**
602
+ * Kick user from group
603
+ */
604
+ async kick(roomId, userId) {
605
+ return this.client.post("/groups.kick", {
606
+ roomId,
607
+ userId,
608
+ });
609
+ }
610
+ /**
611
+ * Leave a group
612
+ */
613
+ async leave(roomId, roomName) {
614
+ const data = {};
615
+ if (roomId)
616
+ data.roomId = roomId;
617
+ if (roomName)
618
+ data.roomName = roomName;
619
+ return this.client.post("/groups.leave", data);
620
+ }
621
+ /**
622
+ * Archive a group
623
+ */
624
+ async archive(roomId, roomName) {
625
+ const data = {};
626
+ if (roomId)
627
+ data.roomId = roomId;
628
+ if (roomName)
629
+ data.roomName = roomName;
630
+ return this.client.post("/groups.archive", data);
631
+ }
632
+ /**
633
+ * Unarchive a group
634
+ */
635
+ async unarchive(roomId, roomName) {
636
+ const data = {};
637
+ if (roomId)
638
+ data.roomId = roomId;
639
+ if (roomName)
640
+ data.roomName = roomName;
641
+ return this.client.post("/groups.unarchive", data);
642
+ }
643
+ /**
644
+ * Delete a group
645
+ */
646
+ async delete(roomId, roomName) {
647
+ const data = {};
648
+ if (roomId)
649
+ data.roomId = roomId;
650
+ if (roomName)
651
+ data.roomName = roomName;
652
+ return this.client.post("/groups.delete", data);
653
+ }
654
+ /**
655
+ * Close a group
656
+ */
657
+ async close(roomId, roomName) {
658
+ const data = {};
659
+ if (roomId)
660
+ data.roomId = roomId;
661
+ if (roomName)
662
+ data.roomName = roomName;
663
+ return this.client.post("/groups.close", data);
664
+ }
665
+ /**
666
+ * Open a group
667
+ */
668
+ async open(roomId, roomName) {
669
+ const data = {};
670
+ if (roomId)
671
+ data.roomId = roomId;
672
+ if (roomName)
673
+ data.roomName = roomName;
674
+ return this.client.post("/groups.open", data);
675
+ }
676
+ /**
677
+ * Set group topic
678
+ */
679
+ async setTopic(roomId, topic) {
680
+ return this.client.post("/groups.setTopic", {
681
+ roomId,
682
+ topic,
683
+ });
684
+ }
685
+ /**
686
+ * Set group description
687
+ */
688
+ async setDescription(roomId, description) {
689
+ return this.client.post("/groups.setDescription", {
690
+ roomId,
691
+ description,
692
+ });
693
+ }
694
+ /**
695
+ * Rename group
696
+ */
697
+ async rename(roomId, name) {
698
+ return this.client.post("/groups.rename", {
699
+ roomId,
700
+ name,
701
+ });
702
+ }
703
+ /**
704
+ * Get group history
705
+ */
706
+ async history(roomId, latest, oldest, inclusive, offset = 0, count = 20) {
707
+ const params = {
708
+ roomId,
709
+ offset,
710
+ count,
711
+ };
712
+ if (latest)
713
+ params.latest = latest.toISOString();
714
+ if (oldest)
715
+ params.oldest = oldest.toISOString();
716
+ if (inclusive !== undefined)
717
+ params.inclusive = inclusive;
718
+ return this.client.get("/groups.history", params);
719
+ }
720
+ /**
721
+ * Get group members
722
+ */
723
+ async members(roomId, roomName, offset = 0, count = 50) {
724
+ const params = {
725
+ offset,
726
+ count,
727
+ };
728
+ if (roomId)
729
+ params.roomId = roomId;
730
+ if (roomName)
731
+ params.roomName = roomName;
732
+ return this.client.get("/groups.members", params);
733
+ }
734
+ }
735
+
736
+ class UserResource {
737
+ constructor(client) {
738
+ this.client = client;
739
+ }
740
+ /**
741
+ * Create a new user
742
+ */
743
+ async create(username, email, password, name, active = true, roles = ["user"], joinDefaultChannels = true, requirePasswordChange = false) {
744
+ return this.client.post("/users.create", {
745
+ username,
746
+ email,
747
+ password,
748
+ name,
749
+ active,
750
+ roles,
751
+ joinDefaultChannels,
752
+ requirePasswordChange,
753
+ });
754
+ }
755
+ /**
756
+ * Get user information
757
+ */
758
+ async info(userId, username) {
759
+ const params = {};
760
+ if (userId)
761
+ params.userId = userId;
762
+ if (username)
763
+ params.username = username;
764
+ return this.client.get("/users.info", params);
765
+ }
766
+ /**
767
+ * List all users
768
+ */
769
+ async list(offset = 0, count = 50, sort, fields, query) {
770
+ const params = {
771
+ offset,
772
+ count,
773
+ };
774
+ if (sort)
775
+ params.sort = JSON.stringify(sort);
776
+ if (fields)
777
+ params.fields = JSON.stringify(fields);
778
+ if (query)
779
+ params.query = JSON.stringify(query);
780
+ return this.client.get("/users.list", params);
781
+ }
782
+ /**
783
+ * Update user
784
+ */
785
+ async update(userId, data) {
786
+ return this.client.post("/users.update", {
787
+ userId,
788
+ data,
789
+ });
790
+ }
791
+ /**
792
+ * Delete user
793
+ */
794
+ async delete(userId, confirmRelinquish = false) {
795
+ return this.client.post("/users.delete", {
796
+ userId,
797
+ confirmRelinquish,
798
+ });
799
+ }
800
+ /**
801
+ * Deactivate user
802
+ */
803
+ async deactivate(userId, confirmRelinquish = false) {
804
+ return this.client.post("/users.deactivate", {
805
+ userId,
806
+ confirmRelinquish,
807
+ });
808
+ }
809
+ /**
810
+ * Get user's own info
811
+ */
812
+ async getMe() {
813
+ return this.client.get("/me");
814
+ }
815
+ /**
816
+ * Get user preferences
817
+ */
818
+ async getPreferences(userId) {
819
+ const params = {};
820
+ if (userId)
821
+ params.userId = userId;
822
+ return this.client.get("/users.getPreferences", params);
823
+ }
824
+ /**
825
+ * Set user preferences
826
+ */
827
+ async setPreferences(userId, preferences) {
828
+ return this.client.post("/users.setPreferences", {
829
+ userId,
830
+ preferences,
831
+ });
832
+ }
833
+ /**
834
+ * Set user status
835
+ */
836
+ async setStatus(message, status) {
837
+ return this.client.post("/users.setStatus", {
838
+ message,
839
+ status,
840
+ });
841
+ }
842
+ /**
843
+ * Get user status
844
+ */
845
+ async getStatus(userId, username) {
846
+ const params = {};
847
+ if (userId)
848
+ params.userId = userId;
849
+ if (username)
850
+ params.username = username;
851
+ return this.client.get("/users.getStatus", params);
852
+ }
853
+ /**
854
+ * Set user avatar
855
+ */
856
+ async setAvatar(userId, avatarUrl, username) {
857
+ const data = { userId };
858
+ if (avatarUrl)
859
+ data.avatarUrl = avatarUrl;
860
+ if (username)
861
+ data.username = username;
862
+ return this.client.post("/users.setAvatar", data);
863
+ }
864
+ /**
865
+ * Reset user avatar
866
+ */
867
+ async resetAvatar(userId, username) {
868
+ const data = { userId };
869
+ if (username)
870
+ data.username = username;
871
+ return this.client.post("/users.resetAvatar", data);
872
+ }
873
+ /**
874
+ * Create user auth token
875
+ */
876
+ async createToken(userId, username) {
877
+ const data = {};
878
+ if (userId)
879
+ data.userId = userId;
880
+ if (username)
881
+ data.username = username;
882
+ return this.client.post("/users.createToken", data);
883
+ }
884
+ /**
885
+ * Get user presence
886
+ */
887
+ async getPresence(userId, username) {
888
+ const params = {};
889
+ if (userId)
890
+ params.userId = userId;
891
+ if (username)
892
+ params.username = username;
893
+ return this.client.get("/users.getPresence", params);
894
+ }
895
+ /**
896
+ * Forgot password
897
+ */
898
+ async forgotPassword(email) {
899
+ return this.client.post("/users.forgotPassword", {
900
+ email,
901
+ });
902
+ }
903
+ /**
904
+ * Register user
905
+ */
906
+ async register(username, email, password, name, secretURL) {
907
+ return this.client.post("/users.register", {
908
+ username,
909
+ email,
910
+ password,
911
+ name,
912
+ secretURL,
913
+ });
914
+ }
915
+ /**
916
+ * Request data download
917
+ */
918
+ async requestDataDownload(fullExport = false) {
919
+ return this.client.get("/users.requestDataDownload", {
920
+ fullExport,
921
+ });
922
+ }
923
+ }
924
+
925
+ class RocketChatSDK {
926
+ constructor(config) {
927
+ this.client = new RocketChatClient(config);
928
+ this.channels = new ChannelResource(this.client);
929
+ this.chat = new ChatResource(this.client);
930
+ this.dm = new DirectMessageResource(this.client);
931
+ this.groups = new GroupResource(this.client);
932
+ this.users = new UserResource(this.client);
933
+ }
934
+ /**
935
+ * Login to RocketChat
936
+ */
937
+ async login(username, password) {
938
+ return this.client.login(username, password);
939
+ }
940
+ /**
941
+ * Logout from RocketChat
942
+ */
943
+ async logout() {
944
+ return this.client.logout();
945
+ }
946
+ /**
947
+ * Get the underlying client for direct API access
948
+ */
949
+ getClient() {
950
+ return this.client;
951
+ }
952
+ }
953
+
954
+ exports.ChannelResource = ChannelResource;
955
+ exports.ChatResource = ChatResource;
956
+ exports.DirectMessageResource = DirectMessageResource;
957
+ exports.GroupResource = GroupResource;
958
+ exports.RocketChatClient = RocketChatClient;
959
+ exports.RocketChatSDK = RocketChatSDK;
960
+ exports.UserResource = UserResource;
961
+ //# sourceMappingURL=index.js.map