@@ -173,3 +173,64 @@ class CipherStoreImpl: CipherStore {
173
173
174
174
getClient(userId = userId).platform().store().registerCipherStore(CipherStoreImpl ());
175
175
```
176
+
177
+ ## SDK-Managed State
178
+
179
+ With ` SDK-Managed State ` , the SDK will be exclusively responsible for the data storage. This means
180
+ that the clients don't need to make any changes themselves, as the implementation is internal to the
181
+ SDK. To add support for an SDK managed ` Repository ` , it needs to be added to the initialization code
182
+ for WASM and UniFFI. This example shows how to add support for ` Cipher ` s.
183
+
184
+ ### WASM
185
+
186
+ Go to ` crates/bitwarden-wasm-internal/src/platform/mod.rs ` and add a line with your type, as shown:
187
+
188
+ ``` rust,ignore
189
+ pub async fn initialize_state(
190
+ &self,
191
+ cipher_repository: CipherRepository,
192
+ ) -> Result<(), bitwarden_state::registry::StateRegistryError> {
193
+ let cipher = cipher_repository.into_channel_impl();
194
+ self.0.platform().state().register_client_managed(cipher);
195
+
196
+ let sdk_managed_repositories = vec![
197
+ // This should list all the SDK-managed repositories
198
+ <Cipher as RepositoryItem>::data(),
199
+ // Add your type here
200
+ ];
201
+
202
+ self.0
203
+ .platform()
204
+ .state()
205
+ .initialize_database(sdk_managed_repositories)
206
+ .await
207
+ }
208
+ ```
209
+
210
+ ### UniFFI
211
+
212
+ Go to ` crates/bitwarden-uniffi/src/platform/mod.rs ` and add a line with your type, as shown:
213
+
214
+ ``` rust,ignore
215
+ pub async fn initialize_state(
216
+ &self,
217
+ cipher_repository: Arc<dyn CipherRepository>,
218
+ ) -> Result<()> {
219
+ let cipher = UniffiRepositoryBridge::new(cipher_repository);
220
+ self.0.platform().state().register_client_managed(cipher);
221
+
222
+ let sdk_managed_repositories = vec![
223
+ // This should list all the SDK-managed repositories
224
+ <Cipher as RepositoryItem>::data(),
225
+ // Add your type here
226
+ ];
227
+
228
+ self.0
229
+ .platform()
230
+ .state()
231
+ .initialize_database(sdk_managed_repositories)
232
+ .await
233
+ .map_err(Error::StateRegistry)?;
234
+ Ok(())
235
+ }
236
+ ```
0 commit comments