mirror of
https://github.com/bitwarden/browser
synced 2026-02-18 02:19:18 +00:00
* feat(user-decryption-options) [PM-26413]: Update UserDecryptionOptionsService and tests to use UserId-only APIs. * feat(user-decryption-options) [PM-26413]: Update InternalUserDecryptionOptionsService call sites to use UserId-only API. * feat(user-decryption-options) [PM-26413] Update userDecryptionOptions$ call sites to use the UserId-only API. * feat(user-decryption-options) [PM-26413]: Update additional call sites. * feat(user-decryption-options) [PM-26413]: Update dependencies and an additional call site. * feat(user-verification-service) [PM-26413]: Replace where allowed by unrestricted imports invocation of UserVerificationService.hasMasterPassword (deprecated) with UserDecryptionOptions.hasMasterPasswordById$. Additional work to complete as tech debt tracked in PM-27009. * feat(user-decryption-options) [PM-26413]: Update for non-null strict adherence. * feat(user-decryption-options) [PM-26413]: Update type safety and defensive returns. * chore(user-decryption-options) [PM-26413]: Comment cleanup. * feat(user-decryption-options) [PM-26413]: Update tests. * feat(user-decryption-options) [PM-26413]: Standardize null-checking on active account id for new API consumption. * feat(vault-timeout-settings-service) [PM-26413]: Add test cases to illustrate null active account from AccountService. * fix(fido2-user-verification-service-spec) [PM-26413]: Update test harness to use FakeAccountService. * fix(downstream-components) [PM-26413]: Prefer use of the getUserId operator in all authenticated contexts for user id provided to UserDecryptionOptionsService. --------- Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { Observable, filter, map } from "rxjs";
|
|
|
|
import {
|
|
SingleUserStateProvider,
|
|
USER_DECRYPTION_OPTIONS_DISK,
|
|
UserKeyDefinition,
|
|
} from "@bitwarden/common/platform/state";
|
|
import { UserId } from "@bitwarden/common/types/guid";
|
|
|
|
import { InternalUserDecryptionOptionsServiceAbstraction } from "../../abstractions/user-decryption-options.service.abstraction";
|
|
import { UserDecryptionOptions } from "../../models";
|
|
|
|
export const USER_DECRYPTION_OPTIONS = new UserKeyDefinition<UserDecryptionOptions>(
|
|
USER_DECRYPTION_OPTIONS_DISK,
|
|
"decryptionOptions",
|
|
{
|
|
deserializer: (decryptionOptions) => UserDecryptionOptions.fromJSON(decryptionOptions),
|
|
clearOn: ["logout"],
|
|
},
|
|
);
|
|
|
|
export class UserDecryptionOptionsService
|
|
implements InternalUserDecryptionOptionsServiceAbstraction
|
|
{
|
|
constructor(private singleUserStateProvider: SingleUserStateProvider) {}
|
|
|
|
userDecryptionOptionsById$(userId: UserId): Observable<UserDecryptionOptions> {
|
|
return this.singleUserStateProvider
|
|
.get(userId, USER_DECRYPTION_OPTIONS)
|
|
.state$.pipe(filter((options): options is UserDecryptionOptions => options != null));
|
|
}
|
|
|
|
hasMasterPasswordById$(userId: UserId): Observable<boolean> {
|
|
return this.userDecryptionOptionsById$(userId).pipe(
|
|
map((options) => options.hasMasterPassword ?? false),
|
|
);
|
|
}
|
|
|
|
async setUserDecryptionOptionsById(
|
|
userId: UserId,
|
|
userDecryptionOptions: UserDecryptionOptions,
|
|
): Promise<void> {
|
|
await this.singleUserStateProvider
|
|
.get(userId, USER_DECRYPTION_OPTIONS)
|
|
.update((_) => userDecryptionOptions);
|
|
}
|
|
}
|