From d506de9f23815a37740456a986ddf9ddde36c51b Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Wed, 2 Mar 2022 16:53:41 -0300 Subject: [PATCH 1/3] Chore: Migrate REST API - e2eGetUsersOfRoomWithoutKey to Typescript (#3793) * Chore: Migrate REST API - e2eGetUsersOfRoomWithoutKey to Typescript * Update app/definitions/rest/v1/e2e.ts Co-authored-by: Gleidson Daniel Silva Co-authored-by: Gleidson Daniel Silva --- app/definitions/rest/v1/e2e.ts | 7 +++++++ app/lib/encryption/room.ts | 4 ++-- app/lib/rocketchat/services/restApi.ts | 4 +--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/definitions/rest/v1/e2e.ts b/app/definitions/rest/v1/e2e.ts index 4e41ef562..b62f312f5 100644 --- a/app/definitions/rest/v1/e2e.ts +++ b/app/definitions/rest/v1/e2e.ts @@ -1,5 +1,12 @@ +import { IUser } from '../../IUser'; + export type E2eEndpoints = { 'e2e.setUserPublicAndPrivateKeys': { POST: (params: { public_key: string; private_key: string }) => void; }; + 'e2e.getUsersOfRoomWithoutKey': { + GET: (params: { rid: string }) => { + users: Pick[]; + }; + }; }; diff --git a/app/lib/encryption/room.ts b/app/lib/encryption/room.ts index a68ccc49f..ee3519207 100644 --- a/app/lib/encryption/room.ts +++ b/app/lib/encryption/room.ts @@ -158,12 +158,12 @@ export default class EncryptionRoom { const result = await RocketChat.e2eGetUsersOfRoomWithoutKey(this.roomId); if (result.success) { const { users } = result; - await Promise.all(users.map((user: IUser) => this.encryptRoomKeyForUser(user))); + await Promise.all(users.map(user => this.encryptRoomKeyForUser(user))); } }; // Encrypt the room key to each user in - encryptRoomKeyForUser = async (user: IUser) => { + encryptRoomKeyForUser = async (user: Pick) => { if (user?.e2e?.public_key) { const { public_key: publicKey } = user.e2e; const userKey = await SimpleCrypto.RSA.importKey(EJSON.parse(publicKey)); diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index a3f148f0a..515269018 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -41,10 +41,8 @@ export const e2eRequestSubscriptionKeys = (): any => // RC 0.72.0 sdk.methodCallWrapper('e2e.requestSubscriptionKeys'); -export const e2eGetUsersOfRoomWithoutKey = (rid: string): any => +export const e2eGetUsersOfRoomWithoutKey = (rid: string) => // RC 0.70.0 - // TODO: missing definitions from server - // @ts-ignore sdk.get('e2e.getUsersOfRoomWithoutKey', { rid }); export const e2eSetRoomKeyID = (rid: string, keyID: string): any => From 529c9f0b00dd66b52d5aef1d3f1930d715df3dee Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Wed, 2 Mar 2022 16:08:56 -0400 Subject: [PATCH 2/3] Chore: Migrate REST API - register to TS (#3796) * Migrate `user.register` to TypeScript --- app/definitions/IUser.ts | 10 ++++++++++ app/definitions/rest/v1/user.ts | 5 ++++- app/lib/rocketchat/services/restApi.ts | 4 +--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/definitions/IUser.ts b/app/definitions/IUser.ts index 474a2105e..e1746554d 100644 --- a/app/definitions/IUser.ts +++ b/app/definitions/IUser.ts @@ -22,6 +22,16 @@ export interface IPersonalAccessToken extends ILoginToken { bypassTwoFactor?: boolean; } +export interface IUserRegistered { + _id: string; + type: string; + status: UserStatus; + active: boolean; + name: string; + username: string; + __rooms: string[]; +} + export interface IUserEmailVerificationToken { token: string; address: string; diff --git a/app/definitions/rest/v1/user.ts b/app/definitions/rest/v1/user.ts index 7de12aabf..b8c37cc17 100644 --- a/app/definitions/rest/v1/user.ts +++ b/app/definitions/rest/v1/user.ts @@ -1,4 +1,4 @@ -import { IUser } from '../../IUser'; +import { IUser, IUserRegistered } from '../../IUser'; export type UserEndpoints = { 'users.info': { @@ -11,4 +11,7 @@ export type UserEndpoints = { success: boolean; }; }; + 'users.register': { + POST: (params: { name: string; email: string; username: string; pass: string }) => { user: IUserRegistered }; + }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 515269018..19217ef12 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -67,10 +67,8 @@ export const updateJitsiTimeout = (roomId: string): any => // @ts-ignore sdk.post('video-conference/jitsi.update-timeout', { roomId }); -export const register = (credentials: any): any => +export const register = (credentials: { name: string; email: string; pass: string; username: string }) => // RC 0.50.0 - // TODO: missing definitions from server - // @ts-ignore sdk.post('users.register', credentials); export const forgotPassword = (email: string): any => From 1da4f01dcb0cc4ece932a3101da8051691021eb1 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Wed, 2 Mar 2022 16:17:42 -0400 Subject: [PATCH 3/3] Chore: Migrate REST API - createTeam to TS (#3788) * Migrate `teams.create` REST API to TypeScript --- app/definitions/rest/v1/teams.ts | 9 +++++++++ app/lib/rocketchat/services/restApi.ts | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/definitions/rest/v1/teams.ts b/app/definitions/rest/v1/teams.ts index 29047149d..cc6bfd620 100644 --- a/app/definitions/rest/v1/teams.ts +++ b/app/definitions/rest/v1/teams.ts @@ -1,7 +1,16 @@ import { IRoom } from '../../IRoom'; +import { ITeam, TEAM_TYPE } from '../../ITeam'; export type TeamsEndpoints = { 'teams.removeRoom': { POST: (params: { roomId: string; teamId: string }) => { room: IRoom }; }; + 'teams.create': { + POST: (params: { + name: string; + users: string[]; + type: TEAM_TYPE; + room: { readOnly: boolean; extraData: { broadcast: boolean; encrypted: boolean } }; + }) => { team: ITeam }; + }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 19217ef12..b5947efae 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -148,7 +148,7 @@ export const createTeam = ({ readOnly: boolean; broadcast: boolean; encrypted: boolean; -}): any => { +}) => { const params = { name, users, @@ -162,8 +162,6 @@ export const createTeam = ({ } }; // RC 3.13.0 - // TODO: missing definitions from server - // @ts-ignore return sdk.post('teams.create', params); }; export const addRoomsToTeam = ({ teamId, rooms }: { teamId: string; rooms: string[] }): any =>