1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 14:34:02 +00:00

introduce generator profile provider

This commit is contained in:
✨ Audrey ✨
2025-01-06 15:34:37 -05:00
parent fd395a53c4
commit 3473ac7ef2
17 changed files with 761 additions and 374 deletions

View File

@@ -3,6 +3,8 @@ import { Observable } from "rxjs";
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
import { OrganizationId, UserId } from "@bitwarden/common/types/guid";
import { Account } from "../auth/abstractions/account.service";
import { OrganizationEncryptor } from "./cryptography/organization-encryptor.abstraction";
import { UserEncryptor } from "./cryptography/user-encryptor.abstraction";
@@ -151,6 +153,25 @@ export type SingleUserDependency = {
singleUserId$: Observable<UserId>;
};
/** A pattern for types that depend upon a fixed account and return
* an observable.
*
* Consumers of this dependency should emit a `UserChangedError` if
* the value of `singleAccount$` changes. If `singleAccount$` completes,
* the consumer should also complete. If `singleAccount$` errors, the
* consumer should also emit the error.
*
* @remarks Check the consumer's documentation to determine how it
* responds to repeat emissions.
*/
export type SingleAccountDependency = {
/** A stream that emits an account when subscribed and the user's account
* is unlocked, and completes when the account is locked or logged out.
* The stream should not emit null or undefined.
*/
singleAccount$: Observable<Account>;
};
/** A pattern for types that emit values exclusively when the dependency
* emits a message.
*

View File

@@ -2,11 +2,11 @@ import { StateProvider } from "@bitwarden/common/platform/state";
import { LegacyEncryptorProvider } from "../cryptography/legacy-encryptor-provider";
import { RuntimeExtensionRegistry } from "./runtime-extension-registry";
import { ExtensionRegistry } from "./extension-registry.abstraction";
export class ExtensionService {
constructor(
private readonly registry: RuntimeExtensionRegistry,
private readonly registry: ExtensionRegistry,
private readonly stateProvider: StateProvider,
private readonly encryptorProvider: LegacyEncryptorProvider,
) {}

View File

@@ -96,6 +96,7 @@ export class UserStateSubject<
*/
constructor(
private key: UserKeyDefinition<State> | ObjectKey<State, Secret, Disclosed>,
// FIXME: `getState` should initialize using a state provider
getState: (key: UserKeyDefinition<unknown>) => SingleUserState<unknown>,
private context: UserStateSubjectDependencies<State, Dependencies>,
) {
@@ -222,7 +223,7 @@ export class UserStateSubject<
// `init$` becomes the accumulator for `scan`
init$.pipe(
first(),
map((init) => [init, null] as const),
map((init) => [init, null] as [State, Dependencies]),
),
input$.pipe(
map((constrained) => constrained.state),
@@ -235,7 +236,7 @@ export class UserStateSubject<
if (shouldUpdate) {
// actual update
const next = this.context.nextValue?.(prev, pending, dependencies) ?? pending;
return [next, dependencies];
return [next, dependencies] as const;
} else {
// false update
return [prev, null];