[PB-5714] Add mail API to the sdk#358
Conversation
src/mail/index.ts
Outdated
| clientName: this.appDetails.clientName, | ||
| clientVersion: this.appDetails.clientVersion, | ||
| token: this.apiSecurity.token, | ||
| workspaceToken: this.apiSecurity.workspaceToken, |
There was a problem hiding this comment.
Is the workspaceToken or the desktopToken going to be needed for the meet server api?
If not, maybe its better to remove them from here 🤔
There was a problem hiding this comment.
You are right, I took this part from drive I think
There was a problem hiding this comment.
nope, copied headersWithToken from meet
There was a problem hiding this comment.
maybe they should be removed from there too haha
|
If you are going to do a new release, remember to update the package.json version |
src/mail/index.ts
Outdated
| */ | ||
| async decryptEmail(email: HybridEncryptedEmail, keys: EmailKeys): Promise<Email> { | ||
| const senderEmail = email.params.sender.email; | ||
| const pk = await this.getUserPublicKeys(senderEmail); |
There was a problem hiding this comment.
What is pk and why it contains the publicKeys while other object (keys) contains the private ones? I feel this confusing unless the pk name is clearer
There was a problem hiding this comment.
pk is the public key of the sender. To decrypt the email, we need both the public key of the person who sent the email and the private key of the receiver. I can rename pk to senderPublicKeys
src/mail/index.ts
Outdated
| */ | ||
| async getPublicKeysOfSeveralUsers(emails: string[]): Promise<UserWithPublicKeys[]> { | ||
| const response = await this.client.getWithParams<{ publicKeys: PublicKeysBase64; user: User }[]>( | ||
| `${this.apiUrl}/getPublicKeysOfSeveralUsers`, |
There was a problem hiding this comment.
This path is not following REST. Something like /users/keys with a body would be better
src/mail/index.ts
Outdated
| */ | ||
| async getUserPublicKeys(userEmail: string): Promise<UserWithPublicKeys> { | ||
| const response = await this.client.getWithParams<{ publicKeys: PublicKeysBase64; user: User }>( | ||
| `${this.apiUrl}/getUserPublicKeys`, |
src/mail/index.ts
Outdated
| * @returns Server response | ||
| */ | ||
| async uploadKeystoreToServer(encryptedKeystore: EncryptedKeystore): Promise<void> { | ||
| return this.client.post(`${this.apiUrl}/uploadKeystore`, { encryptedKeystore }, this.headers()); |
There was a problem hiding this comment.
And here:
POST /keys
Would be better
src/mail/index.ts
Outdated
| * @returns Server response | ||
| */ | ||
| async sendEncryptedEmail(email: HybridEncryptedEmail): Promise<void> { | ||
| return this.client.post(`${this.apiUrl}/sendEncryptedEmail`, { email }, this.headers()); |
There was a problem hiding this comment.
Same here
POST /mails
Would be more correct
src/mail/index.ts
Outdated
| * @returns Server response | ||
| */ | ||
| async sendEncryptedEmailToMultipleRecipients(emails: HybridEncryptedEmail[]): Promise<void> { | ||
| return this.client.post(`${this.apiUrl}/sendEncryptedEmailToMultipleRecipients`, { emails }, this.headers()); |
src/mail/index.ts
Outdated
| * @returns Server response | ||
| */ | ||
| async sendPwdProtectedEmail(email: PwdProtectedEmail): Promise<void> { | ||
| return this.client.post(`${this.apiUrl}/sendPwdProtectedEmail`, { email }, this.headers()); |
src/mail/index.ts
Outdated
| * @returns The encrypted keystore | ||
| */ | ||
| async downloadKeystoreFromServer(userEmail: string, keystoreType: KeystoreType): Promise<EncryptedKeystore> { | ||
| return this.client.getWithParams(`${this.apiUrl}/getKeystore`, { userEmail, keystoreType }, this.headers()); |
|
@sg-gs I've changed the paths, now they are:
|
@TamaraFinogina
Idea: Same action but additional params → same route (generally) |
yeah agreed, only the get keys requests seem like a POST to me, so we avoid sending the emails in query params as I know there is a max url limit (though I have no clue how big or small this limit is) or avoid possiby exposing recipients in a server request log |
|
@sg-gs @jzunigax2, functions now are the following:
All of them are currently POST because P.S. I'm not sure if |
| const singleResponse = response[0]; | ||
| const publicKeys = await base64ToPublicKey(singleResponse.publicKeys); |
There was a problem hiding this comment.
singleResponse.publicKeys will throw if the server returns an empty array
Consider adding a guard:
if (!response[0]) throw new Error(No public keys found for ${userEmail});
There was a problem hiding this comment.
Done, check is added
| "uuid": "13.0.0" | ||
| "uuid": "13.0.0", | ||
| "internxt-crypto": "https://github.com/internxt/crypto/releases/download/v.0.0.12/internxt-crypto-0.0.12.tgz" | ||
|
|
There was a problem hiding this comment.
Need to create a task to release this package to npm
There was a problem hiding this comment.
Yes, I'm preparing the release
There was a problem hiding this comment.
Done, it uses version 0.0.13 now
test/mail/index.test.ts
Outdated
| ]); | ||
| }); | ||
|
|
||
| it('should successfully create and upload a keystore', async () => { |
There was a problem hiding this comment.
something like:
'When a keystore upload is requested, then it should successfully upload the keystore.'?
This PR adds functions needed for implementing Mail