-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert papers/contacts to CipherData instead of CipherResponse #184
Conversation
3e718c3
to
0d0abc1
Compare
We did not implement these methods that allow to create a CipherData from a Cipher. But we will need them soon to convert more easily paper and contact to ciphers. We also complete toFieldData method.
We were converting papers/contacts to CipherResponse because it is the model used by default during the sync. Here we choose to convert to CipherData instead because : - it will help us add a fallback to the sync. When papers/contacts sync will fail, we will be able to use the previous papers/contacts stored locally (they are stored as CipherData) - the conversion is simplier (it involves less classes) - we can still inject our papers/contacts during the sync thanks to the upsert method
We need the encryption key to convert papers/contacts. So if we try to do a sync when the vault is locked, we will have no papers/contacts. In some case, another sync is triggered when we unvault the lock, but if we unlock the vault when the previous sync is still in progress AND previous sync already passed the papers/contacts conversion (which failed), it can result to empty papers/contacts. In this case, we want to reuse stored papers/contacts.
response.ciphers.push(...papersPromise.value); | ||
console.log(`${papersPromise.value.length} contacts ciphers will be added`); | ||
|
||
await this.cipherService.upsert(papersPromise.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care, each upsert will trigger the localstorage serialization. By doing this instead of using the in-memory response.ciphers
my understanding is that we will add 2 serializations to the sync process (one for papers, one for contacts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Ideas :
- I can easily do 1 upsert for both papers and contacts.
- I can also modify syncCiphers to take in parameters papers and contacts as CipherData (and also of course bitwarden ciphers as CipherReponse). It should be easy but at first I wanted to avoid modifying syncCiphers. What do you think about it?
libs/cozy/contact.helper.ts
Outdated
key?: SymmetricCryptoKey | ||
): Promise<CipherResponse> => { | ||
): Promise<CipherData> => { | ||
// Temporary type fix becayse contact.cozyMetadata is not properly typed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Temporary type fix becayse contact.cozyMetadata is not properly typed | |
// Temporary type fix because contact.cozyMetadata is not properly typed |
We were converting papers/contacts to CipherResponse because it is the model used by default during the sync.
Here we choose to convert to CipherData instead because :