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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RocketChat SDK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # RocketChat SDK
2
+
3
+ A comprehensive TypeScript SDK for the RocketChat API, providing easy-to-use methods for interacting with RocketChat servers.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Full TypeScript support** with comprehensive type definitions
8
+ - 📦 **Modular architecture** with organized resource classes
9
+ - 🔐 **Authentication handling** with automatic token management
10
+ - 🌐 **HTTP client abstraction** built on Axios
11
+ - 📚 **Complete API coverage** for channels, groups, direct messages, users, and chat
12
+ - 🛠️ **Built-in error handling** with structured response types
13
+ - 📖 **Extensive documentation** with code examples
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install rocketchat-sdk
19
+ # or
20
+ yarn add rocketchat-sdk
21
+ # or
22
+ pnpm add rocketchat-sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### Basic Setup
28
+
29
+ ```typescript
30
+ import { RocketChatSDK } from "rocketchat-sdk";
31
+
32
+ const rocketChat = new RocketChatSDK({
33
+ baseUrl: "https://your-rocketchat-server.com",
34
+ username: "your-username",
35
+ password: "your-password",
36
+ });
37
+
38
+ // Login
39
+ const loginResult = await rocketChat.login();
40
+ if (loginResult.success) {
41
+ console.log("Logged in successfully!");
42
+ }
43
+ ```
44
+
45
+ ### Using Auth Token
46
+
47
+ ```typescript
48
+ const rocketChat = new RocketChatSDK({
49
+ baseUrl: "https://your-rocketchat-server.com",
50
+ userId: "your-user-id",
51
+ authToken: "your-auth-token",
52
+ });
53
+ ```
54
+
55
+ ## API Reference
56
+
57
+ ### Chat Operations
58
+
59
+ #### Send a Message
60
+
61
+ ```typescript
62
+ const result = await rocketChat.chat.postMessage(
63
+ "roomId",
64
+ "Hello, World!",
65
+ "BotAlias", // optional alias
66
+ "🚀", // optional emoji
67
+ "avatar-url", // optional avatar
68
+ );
69
+
70
+ if (result.success) {
71
+ console.log("Message sent:", result.data.message);
72
+ }
73
+ ```
74
+
75
+ #### Update a Message
76
+
77
+ ```typescript
78
+ await rocketChat.chat.update("roomId", "messageId", "Updated message text");
79
+ ```
80
+
81
+ #### Delete a Message
82
+
83
+ ```typescript
84
+ await rocketChat.chat.delete("roomId", "messageId");
85
+ ```
86
+
87
+ #### React to a Message
88
+
89
+ ```typescript
90
+ await rocketChat.chat.react("messageId", "👍", true); // add reaction
91
+ await rocketChat.chat.react("messageId", "👍", false); // remove reaction
92
+ ```
93
+
94
+ ### Channel Operations
95
+
96
+ #### Create a Channel
97
+
98
+ ```typescript
99
+ const result = await rocketChat.channels.create(
100
+ "general-discussion",
101
+ ["user1", "user2"], // optional members
102
+ false, // readOnly flag
103
+ );
104
+ ```
105
+
106
+ #### Get Channel Info
107
+
108
+ ```typescript
109
+ const info = await rocketChat.channels.info("channelId");
110
+ // or by name
111
+ const info = await rocketChat.channels.info(undefined, "general");
112
+ ```
113
+
114
+ #### Join a Channel
115
+
116
+ ```typescript
117
+ await rocketChat.channels.join("channelId");
118
+ // or by name
119
+ await rocketChat.channels.join(undefined, "general");
120
+ ```
121
+
122
+ #### List All Channels
123
+
124
+ ```typescript
125
+ const channels = await rocketChat.channels.list(0, 50); // offset, count
126
+ ```
127
+
128
+ #### Invite User to Channel
129
+
130
+ ```typescript
131
+ await rocketChat.channels.invite("channelId", "userId");
132
+ ```
133
+
134
+ ### Group Operations
135
+
136
+ #### Create a Private Group
137
+
138
+ ```typescript
139
+ const result = await rocketChat.groups.create(
140
+ "private-team",
141
+ ["user1", "user2"],
142
+ false, // readOnly
143
+ );
144
+ ```
145
+
146
+ #### Get Group Members
147
+
148
+ ```typescript
149
+ const members = await rocketChat.groups.members("groupId");
150
+ ```
151
+
152
+ ### Direct Message Operations
153
+
154
+ #### Create Direct Message
155
+
156
+ ```typescript
157
+ const dm = await rocketChat.dm.create("username");
158
+ ```
159
+
160
+ #### Get DM History
161
+
162
+ ```typescript
163
+ const history = await rocketChat.dm.history(
164
+ "roomId",
165
+ new Date(), // latest
166
+ undefined, // oldest
167
+ true, // inclusive
168
+ 0, // offset
169
+ 20, // count
170
+ );
171
+ ```
172
+
173
+ ### User Operations
174
+
175
+ #### Get User Info
176
+
177
+ ```typescript
178
+ const user = await rocketChat.users.info("userId");
179
+ // or by username
180
+ const user = await rocketChat.users.info(undefined, "john.doe");
181
+ ```
182
+
183
+ #### Create User
184
+
185
+ ```typescript
186
+ const newUser = await rocketChat.users.create(
187
+ "john.doe", // username
188
+ "john@example.com", // email
189
+ "securePassword123", // password
190
+ "John Doe", // name
191
+ true, // active
192
+ ["user"], // roles
193
+ true, // joinDefaultChannels
194
+ false, // requirePasswordChange
195
+ );
196
+ ```
197
+
198
+ #### Set User Status
199
+
200
+ ```typescript
201
+ await rocketChat.users.setStatus("Working on awesome features!", "busy");
202
+ ```
203
+
204
+ #### List All Users
205
+
206
+ ```typescript
207
+ const users = await rocketChat.users.list(0, 50);
208
+ ```
209
+
210
+ ## Configuration Options
211
+
212
+ ```typescript
213
+ interface RocketChatConfig {
214
+ baseUrl: string; // RocketChat server URL
215
+ userId?: string; // User ID (for token auth)
216
+ authToken?: string; // Auth token (for token auth)
217
+ username?: string; // Username (for password auth)
218
+ password?: string; // Password (for password auth)
219
+ }
220
+ ```
221
+
222
+ ## Response Format
223
+
224
+ All API methods return a standardized response format:
225
+
226
+ ```typescript
227
+ interface RocketChatResponse<T = any> {
228
+ success: boolean;
229
+ data?: T;
230
+ error?: string;
231
+ errorType?: string;
232
+ }
233
+ ```
234
+
235
+ ### Handling Responses
236
+
237
+ ```typescript
238
+ const result = await rocketChat.chat.postMessage("roomId", "Hello!");
239
+
240
+ if (result.success) {
241
+ // Success case
242
+ console.log("Message:", result.data.message);
243
+ } else {
244
+ // Error case
245
+ console.error("Error:", result.error);
246
+ }
247
+ ```
248
+
249
+ ## Error Handling
250
+
251
+ The SDK provides comprehensive error handling:
252
+
253
+ ```typescript
254
+ try {
255
+ const result = await rocketChat.channels.create("test-channel");
256
+ if (!result.success) {
257
+ console.error("Failed to create channel:", result.error);
258
+ }
259
+ } catch (error) {
260
+ console.error("Network or unexpected error:", error);
261
+ }
262
+ ```
263
+
264
+ ## Advanced Usage
265
+
266
+ ### Direct Client Access
267
+
268
+ For advanced use cases, you can access the underlying HTTP client:
269
+
270
+ ```typescript
271
+ const client = rocketChat.getClient();
272
+ const customResult = await client.get("/custom-endpoint");
273
+ ```
274
+
275
+ ### Custom Headers and Configuration
276
+
277
+ The SDK uses Axios internally. You can extend functionality by accessing the client:
278
+
279
+ ```typescript
280
+ const client = rocketChat.getClient();
281
+ // Add custom interceptors, headers, etc.
282
+ ```
283
+
284
+ ## TypeScript Support
285
+
286
+ The SDK is built with TypeScript and provides comprehensive type definitions:
287
+
288
+ ```typescript
289
+ import {
290
+ RocketChatSDK,
291
+ RocketChatConfig,
292
+ Channel,
293
+ Message,
294
+ User,
295
+ } from "rocketchat-sdk";
296
+
297
+ // All types are fully typed
298
+ const config: RocketChatConfig = {
299
+ baseUrl: "https://chat.example.com",
300
+ username: "admin",
301
+ password: "password",
302
+ };
303
+
304
+ const sdk = new RocketChatSDK(config);
305
+ ```
306
+
307
+ ## Building from Source
308
+
309
+ 1. Clone the repository
310
+ 2. Install dependencies: `npm install`
311
+ 3. Build: `npm run build`
312
+ 4. Test: `npm test`
313
+ 5. Lint: `npm run lint`
314
+
315
+ ## Contributing
316
+
317
+ 1. Fork the repository
318
+ 2. Create a feature branch
319
+ 3. Make your changes
320
+ 4. Add tests
321
+ 5. Run the linter and tests
322
+ 6. Submit a pull request
323
+
324
+ ## License
325
+
326
+ MIT License - see [LICENSE](LICENSE) file for details.
327
+
328
+ ## Support
329
+
330
+ - 📖 [API Documentation](https://developer.rocket.chat/reference/api)
331
+ - 🐛 [Report Issues](https://github.com/yourusername/rocketchat-sdk/issues)
332
+ - 💬 [Discussions](https://github.com/yourusername/rocketchat-sdk/discussions)
333
+
334
+ ## Changelog
335
+
336
+ ### v1.0.0
337
+
338
+ - Initial release
339
+ - Full TypeScript support
340
+ - Complete API coverage for core features
341
+ - Authentication handling
342
+ - Comprehensive error handling
@@ -0,0 +1,17 @@
1
+ import { RocketChatConfig, RocketChatResponse } from "./types";
2
+ export declare class RocketChatClient {
3
+ private api;
4
+ private config;
5
+ constructor(config: RocketChatConfig);
6
+ login(username?: string, password?: string): Promise<RocketChatResponse<{
7
+ authToken: string;
8
+ userId: string;
9
+ me: any;
10
+ }>>;
11
+ logout(): Promise<RocketChatResponse>;
12
+ get<T = any>(endpoint: string, params?: Record<string, any>): Promise<RocketChatResponse<T>>;
13
+ post<T = any>(endpoint: string, data?: any): Promise<RocketChatResponse<T>>;
14
+ put<T = any>(endpoint: string, data?: any): Promise<RocketChatResponse<T>>;
15
+ delete<T = any>(endpoint: string): Promise<RocketChatResponse<T>>;
16
+ }
17
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE/D,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IAmB9B,KAAK,CACT,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CACR,kBAAkB,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,GAAG,CAAA;KAAE,CAAC,CACnE;IA+BK,MAAM,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAerC,GAAG,CAAC,CAAC,GAAG,GAAG,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAe3B,IAAI,CAAC,CAAC,GAAG,GAAG,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAe3B,GAAG,CAAC,CAAC,GAAG,GAAG,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAe3B,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAcxE"}
@@ -0,0 +1,40 @@
1
+ import { RocketChatClient } from "./client";
2
+ import { RocketChatConfig } from "./types";
3
+ import { ChannelResource } from "./resources/channelResource";
4
+ import { ChatResource } from "./resources/chatResource";
5
+ import { DirectMessageResource } from "./resources/dmResource";
6
+ import { GroupResource } from "./resources/groupResource";
7
+ import { UserResource } from "./resources/userResource";
8
+ export declare class RocketChatSDK {
9
+ private client;
10
+ channels: ChannelResource;
11
+ chat: ChatResource;
12
+ dm: DirectMessageResource;
13
+ groups: GroupResource;
14
+ users: UserResource;
15
+ constructor(config: RocketChatConfig);
16
+ /**
17
+ * Login to RocketChat
18
+ */
19
+ login(username?: string, password?: string): Promise<import("./types").RocketChatResponse<{
20
+ authToken: string;
21
+ userId: string;
22
+ me: any;
23
+ }>>;
24
+ /**
25
+ * Logout from RocketChat
26
+ */
27
+ logout(): Promise<import("./types").RocketChatResponse<any>>;
28
+ /**
29
+ * Get the underlying client for direct API access
30
+ */
31
+ getClient(): RocketChatClient;
32
+ }
33
+ export * from "./types";
34
+ export { RocketChatClient } from "./client";
35
+ export { ChannelResource } from "./resources/channelResource";
36
+ export { ChatResource } from "./resources/chatResource";
37
+ export { DirectMessageResource } from "./resources/dmResource";
38
+ export { GroupResource } from "./resources/groupResource";
39
+ export { UserResource } from "./resources/userResource";
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAmB;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,EAAE,qBAAqB,CAAC;IAC1B,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;gBAEf,MAAM,EAAE,gBAAgB;IASpC;;OAEG;IACG,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;;;;;IAIhD;;OAEG;IACG,MAAM;IAIZ;;OAEG;IACH,SAAS;CAGV;AAGD,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}