Skip to content
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

Merged
merged 6 commits into from
Apr 22, 2024

Conversation

zatteo
Copy link

@zatteo zatteo commented Apr 19, 2024

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 help us add a fallback to the sync. When papers/contacts sync fail, we 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

@zatteo zatteo force-pushed the feat/update-cozy-client branch 3 times, most recently from 3e718c3 to 0d0abc1 Compare April 20, 2024 08:28
@delete-merged-branch delete-merged-branch bot deleted the branch feat/stream1 April 20, 2024 08:36
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.
@zatteo zatteo changed the base branch from feat/update-cozy-client to feat/stream1 April 22, 2024 08:42
response.ciphers.push(...papersPromise.value);
console.log(`${papersPromise.value.length} contacts ciphers will be added`);

await this.cipherService.upsert(papersPromise.value);
Copy link
Member

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).

Copy link
Author

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?

key?: SymmetricCryptoKey
): Promise<CipherResponse> => {
): Promise<CipherData> => {
// Temporary type fix becayse contact.cozyMetadata is not properly typed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Temporary type fix becayse contact.cozyMetadata is not properly typed
// Temporary type fix because contact.cozyMetadata is not properly typed

@zatteo zatteo merged commit 841a5f9 into feat/stream1 Apr 22, 2024
1 check passed
@delete-merged-branch delete-merged-branch bot deleted the refacto/cipher branch April 22, 2024 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants