[_] make subject encryption optional, add standard errors#59
Conversation
| if (!body.text) { | ||
| throw new InvalidInputEmail(); |
There was a problem hiding this comment.
You can move this outside the try/catch, so it will throw the error directly. Then you won't need to do if(error instance InvalidInputEmail) throw error;, it will be thrower directly.
| if (!body.text || !body.subject) { | ||
| throw new InvalidInputEmail(); |
| * @returns The resulting encrypted email body and symmetric key used for encryption | ||
| */ | ||
| export async function encryptEmailBodyAndSubject( | ||
| body: EmailBodyAndSubject, |
There was a problem hiding this comment.
Change the name of this variable. You are receiving subject and body, not just the body. You can call it email or something like that. It's confusing encrypting subject and body and get 1 param get body.
| * @returns The resulting encrypted email body and symmetric key used for encryption | ||
| */ | ||
| export async function encryptEmailBodyAndSubjectWithKey( | ||
| body: EmailBodyAndSubject, |
| * @returns The resulting decrypted email body | ||
| */ | ||
| export async function decryptEmailBodyAndSubject( | ||
| encEmailBody: EmailBodyAndSubjectEncrypted, |
| * @returns The encrypted email body | ||
| */ | ||
| export async function encryptEmailAndSubjectHybrid( | ||
| body: EmailBodyAndSubject, |
| if (!recipients || recipients.length === 0) { | ||
| throw new InvalidInputEmail(); | ||
| } |
There was a problem hiding this comment.
Move this outside of try/catch so it will be thrown directly
| return encryptedEmails; | ||
| } catch (error) { | ||
| throw new Error('Failed to encrypt email to multiple recipients with hybrid encryption', { cause: error }); | ||
| if (error instanceof InvalidInputEmail) throw error; |
There was a problem hiding this comment.
moving the if outside the try/catch (previous review) you can remove this check.
| * @returns The password-protected email | ||
| */ | ||
| export async function createPwdProtectedEmailAndSubject( | ||
| emailBody: EmailBodyAndSubject, |
| text: 'test body', | ||
| }; | ||
|
|
||
| const emailAndSubject: EmailBodyAndSubject = { |
There was a problem hiding this comment.
nit: would be nice to get this from a fixtures factory. So you can do getEmail() instead of repeating the object in each test.
Also, if you need to update any field:
const getEmail = (overrides: Partial<EmailBodyAndSubject> => ({ text: ..., subject: ...., ...overrides })
[_] Fix sonar and build
[_] Small fixes
|


Description
Makes subject encryption in emails optional and adds error types
Checklist
Testing Process
unit tests
Additional Notes
Not sure why Sonor Cloud doesn't detect coverage