@ethora/sdk-backend 26.2.1 → 26.2.2

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.
Files changed (2) hide show
  1. package/README.md +238 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -217,6 +217,28 @@ router.post(
217
217
  },
218
218
  );
219
219
 
220
+ // Remove user access from chat room
221
+ router.delete(
222
+ '/workspaces/:workspaceId/chat/users/:userId',
223
+ async (req: Request, res: Response) => {
224
+ try {
225
+ const { workspaceId, userId } = req.params;
226
+
227
+ await chatService.removeUserAccessFromChatRoom(workspaceId, userId);
228
+ res.json({ success: true, message: 'Access removed' });
229
+ } catch (error) {
230
+ if (axios.isAxiosError(error)) {
231
+ res.status(error.response?.status || 500).json({
232
+ error: 'Failed to remove access',
233
+ details: error.response?.data,
234
+ });
235
+ } else {
236
+ res.status(500).json({ error: 'Internal server error' });
237
+ }
238
+ }
239
+ },
240
+ );
241
+
220
242
  // Generate client JWT token
221
243
  router.get('/users/:userId/chat-token', (req: Request, res: Response) => {
222
244
  try {
@@ -516,7 +538,44 @@ async function addUserToWorkspace(workspaceId: string, userId: string) {
516
538
  }
517
539
  ```
518
540
 
519
- ### Use Case 4: Cleanup on Workspace Deletion
541
+ ### Use Case 4: Removing User from Workspace
542
+
543
+ When removing a user from a workspace:
544
+
545
+ ```typescript
546
+ async function removeUserFromWorkspace(workspaceId: string, userId: string) {
547
+ const chatService = getEthoraSDKService();
548
+
549
+ try {
550
+ // Remove access from workspace chat room
551
+ await chatService.removeUserAccessFromChatRoom(workspaceId, userId);
552
+
553
+ return { success: true };
554
+ } catch (error) {
555
+ console.error('Failed to remove user from workspace:', error);
556
+ throw error;
557
+ }
558
+ }
559
+
560
+ // Remove multiple users at once
561
+ async function removeMultipleUsersFromWorkspace(
562
+ workspaceId: string,
563
+ userIds: string[],
564
+ ) {
565
+ const chatService = getEthoraSDKService();
566
+
567
+ try {
568
+ await chatService.removeUserAccessFromChatRoom(workspaceId, userIds);
569
+ return { success: true };
570
+ } catch (error) {
571
+ console.error('Failed to remove users from workspace:', error);
572
+ throw error;
573
+ }
574
+ }
575
+ ```
576
+
577
+ ### Use Case 5: Cleanup on Workspace Deletion
578
+
520
579
 
521
580
  When deleting a workspace:
522
581
 
@@ -545,7 +604,7 @@ async function cleanupWorkspaceChat(workspaceId: string, userIds: string[]) {
545
604
  }
546
605
  ```
547
606
 
548
- ### Use Case 5: Getting Users
607
+ ### Use Case 6: Getting Users
549
608
 
550
609
  Retrieve users from the chat service:
551
610
 
@@ -576,7 +635,7 @@ async function getUsersExample() {
576
635
  }
577
636
  ```
578
637
 
579
- ### Use Case 6: Updating Users (Batch)
638
+ ### Use Case 7: Updating Users (Batch)
580
639
 
581
640
  Update multiple users at once:
582
641
 
@@ -621,8 +680,184 @@ async function updateUsersExample() {
621
680
  }
622
681
  ```
623
682
 
683
+ ## API Reference
684
+
685
+ ### Core Methods
686
+
687
+ #### `createUser(userId: UUID, userData?: Record<string, unknown>): Promise<ApiResponse>`
688
+
689
+ Creates a user in the chat service using the `/v2/users/batch` endpoint.
690
+
691
+ **Parameters:**
692
+ - `userId` (UUID): The unique identifier of the user
693
+ - `userData` (optional): Additional user data
694
+ - `firstName` (string): User's first name
695
+ - `lastName` (string): User's last name (minimum 2 characters)
696
+ - `email` (string): User's email address
697
+ - `password` (string): User's password
698
+ - `displayName` (string): Display name (will be split into firstName/lastName if needed)
699
+
700
+ **Returns:** Promise resolving to the API response
701
+
702
+ **Note:** The API requires `lastName` to be at least 2 characters. If not provided or too short, defaults to "User".
703
+
704
+ ---
705
+
706
+ #### `createChatRoom(chatId: UUID, roomData?: Record<string, unknown>): Promise<ApiResponse>`
707
+
708
+ Creates a chat room using the `/v2/chats` endpoint.
709
+
710
+ **Parameters:**
711
+ - `chatId` (UUID): The unique identifier of the chat/workspace
712
+ - `roomData` (optional): Room configuration
713
+ - `title` (string): Chat room title
714
+ - `uuid` (string): Room UUID (defaults to chatId)
715
+ - `type` (string): Room type (defaults to "group")
716
+
717
+ **Returns:** Promise resolving to the API response
718
+
719
+ ---
720
+
721
+ #### `grantUserAccessToChatRoom(chatId: UUID, userId: UUID | UUID[]): Promise<ApiResponse>`
722
+
723
+ Grants user(s) access to a chat room using the `/v2/chats/users-access` endpoint.
724
+
725
+ **Parameters:**
726
+ - `chatId` (UUID): The unique identifier of the chat/workspace
727
+ - `userId` (UUID | UUID[]): Single user ID or array of user IDs
728
+
729
+ **Returns:** Promise resolving to the API response
730
+
731
+ **Note:** User IDs are automatically prefixed with `{appId}_` if they don't already have the prefix.
732
+
733
+ ---
734
+
735
+ #### `removeUserAccessFromChatRoom(chatId: UUID, userId: UUID | UUID[]): Promise<ApiResponse>`
736
+
737
+ Removes user(s) access from a chat room using the `/v2/chats/users-access` DELETE endpoint.
738
+
739
+ **Parameters:**
740
+ - `chatId` (UUID): The unique identifier of the chat/workspace
741
+ - `userId` (UUID | UUID[]): Single user ID or array of user IDs to remove
742
+
743
+ **Returns:** Promise resolving to the API response
744
+
745
+ **Note:** User IDs are automatically prefixed with `{appId}_` if they don't already have the prefix.
746
+
747
+ ---
748
+
749
+ #### `grantChatbotAccessToChatRoom(chatId: UUID): Promise<ApiResponse>`
750
+
751
+ Grants chatbot access to a chat room.
752
+
753
+ **Parameters:**
754
+ - `chatId` (UUID): The unique identifier of the chat/workspace
755
+
756
+ **Returns:** Promise resolving to the API response
757
+
758
+ **Requires:** `ETHORA_CHAT_BOT_JID` environment variable to be set
759
+
760
+ ---
761
+
762
+ #### `getUsers(params?: GetUsersQueryParams): Promise<ApiResponse>`
763
+
764
+ Retrieves users from the chat service using the `/v2/chats/users` endpoint.
765
+
766
+ **Parameters:**
767
+ - `params` (GetUsersQueryParams, optional): Query parameters
768
+ - `chatName` (string): Filter by chat name
769
+ - Group chats: `appId_chatId` format
770
+ - 1-on-1 chats: `xmppUsernameA-xmppUsernameB` format
771
+ - `xmppUsername` (string): Filter by specific XMPP username
772
+
773
+ **Query Modes:**
774
+ - No parameters: Returns all users of the app
775
+ - With `chatName`: Returns all users of the specified chat
776
+ - With `xmppUsername`: Returns a specific user
777
+
778
+ **Returns:** Promise resolving to the API response with users array
779
+
780
+ ---
781
+
782
+ #### `updateUsers(users: UpdateUserData[]): Promise<ApiResponse>`
783
+
784
+ Updates multiple users at once using the `/v2/chats/users` PATCH endpoint.
785
+
786
+ **Parameters:**
787
+ - `users` (UpdateUserData[]): Array of user data to update (1-100 users)
788
+ - `xmppUsername` (string, required): XMPP username to identify the user
789
+ - `firstName` (string, optional): First name
790
+ - `lastName` (string, optional): Last name
791
+ - `username` (string, optional): Username
792
+ - `profileImage` (string, optional): Profile image URL
793
+
794
+ **Returns:** Promise resolving to the API response with results array
795
+
796
+ **Response Status Values:**
797
+ - `updated`: User was successfully updated (includes updated user data)
798
+ - `not-found`: User was not found
799
+ - `skipped`: User update was skipped
800
+
801
+ **Limits:** 1-100 users per request
802
+
803
+ ---
804
+
805
+ #### `deleteUsers(userIds: UUID[]): Promise<ApiResponse>`
806
+
807
+ Deletes users from the chat service using the `/v1/users/batch` endpoint.
808
+
809
+ **Parameters:**
810
+ - `userIds` (UUID[]): Array of user IDs to delete
811
+
812
+ **Returns:** Promise resolving to the API response
813
+
814
+ **Note:** Gracefully handles non-existent users (422 status with "not found").
815
+
816
+ ---
817
+
818
+ #### `deleteChatRoom(chatId: UUID): Promise<ApiResponse>`
819
+
820
+ Deletes a chat room using the `/v1/chats` endpoint.
821
+
822
+ **Parameters:**
823
+ - `chatId` (UUID): The unique identifier of the chat/workspace
824
+
825
+ **Returns:** Promise resolving to the API response
826
+
827
+ **Note:** Gracefully handles non-existent rooms (422 status with "not found").
828
+
829
+ ---
830
+
831
+ ### Helper Methods
832
+
833
+ #### `createChatName(chatId: UUID, full?: boolean): string`
834
+
835
+ Generates a chat room JID from a chat ID.
836
+
837
+ **Parameters:**
838
+ - `chatId` (UUID): The unique identifier of the chat
839
+ - `full` (boolean, optional): Whether to include the full JID domain (default: true)
840
+
841
+ **Returns:** The JID string
842
+ - Full: `{appId}_{chatId}@conference.xmpp.ethoradev.com`
843
+ - Short: `{appId}_{chatId}`
844
+
845
+ ---
846
+
847
+ #### `createChatUserJwtToken(userId: UUID): string`
848
+
849
+ Creates a client-side JWT token for user authentication.
850
+
851
+ **Parameters:**
852
+ - `userId` (UUID): The unique identifier of the user
853
+
854
+ **Returns:** The encoded JWT token for client-side authentication
855
+
856
+ ---
857
+
624
858
  ## Error Handling
625
859
 
860
+
626
861
  ### Handling API Errors
627
862
 
628
863
  The SDK uses Axios for HTTP requests, so errors are AxiosError instances:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethora/sdk-backend",
3
- "version": "26.02.01",
3
+ "version": "26.02.02",
4
4
  "description": "TypeScript SDK for integrating with Ethora chat service backend API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",