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