[PM-16792] [PM-16822] Encapsulate encryptor and state provision within UserStateSubject
#13195
+948
โ880
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
๐๏ธ Tracking
https://bitwarden.atlassian.net/browse/PM-16792
https://bitwarden.atlassian.net/browse/PM-16822
๐ Objective
Encapsulate encryptor and state provision within
UserStateSubject
.This PR also hoists the
userId$
into anaccount$
dependency to ensure consistent user lifetime tracking from the host UI all the way through to theUserStateSubject
. This helps avoid read/write sync bugs withCredentialGeneratorService
apis, similar to those described in PM-11866.๐ฆ Breaking changes
account$
or[account]
bindings:CredentialGeneratorService
UserStateSubject
UserStateSubject
requires a providers object containing service dependenciesObjectKey
; this was required๐ฆ System evolution - Binding
My first pass through standardized observable definitions was tightly coupled to types and stream names. The behaviors, however, aren't typically type or name dependent. Bindings fix this by using generic mapped types that describe their expected behaviors while leaving the dependency name and type free-to-change.
The
account$
binding is the first to be introduced. It represents data that is "pinned" to a specific state. That state emits its data once when subscribed and completes when the data should be discarded from memory.At present the "Dependency" name is still being used. This is likely to change in a future PR, once more kinds of bindings exist.
๐ฆ System evolution - Semantic Loggers
I created a semantic logging feature by accident.
Debugging the user state key is a daunting task using a debugger. You have to know all the right places to put tracepoints to observe what's happening and breakpoints cause timing problems. Setting everything up is a chore, and in order to fix unit tests I found myself instrumenting the code with lots of repetitive console logs.
I decided to leave them in, but didn't want them active in production, so I extracted them into a logger type and stubbed it to disable logging. Then realized I'd made a semantic logger.
โฐ Reminders before review
There are a few places where I needed to look at the actual state while debugging. I marked those with an โ in the actual code. I think I got them all, but if you see that emoji it's code I need to clean up.
๐ฆฎ Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or โน๏ธ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or ๐ญ (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or โป๏ธ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes