-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
active-user-state-provider.factory.ts
36 lines (31 loc) · 1.34 KB
/
active-user-state-provider.factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ActiveUserStateProvider } from "@bitwarden/common/platform/state";
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
import { DefaultActiveUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-active-user-state.provider";
import {
AccountServiceInitOptions,
accountServiceFactory,
} from "../../../auth/background/service-factories/account-service.factory";
import { CachedServices, FactoryOptions, factory } from "./factory-options";
import {
SingleUserStateProviderInitOptions,
singleUserStateProviderFactory,
} from "./single-user-state-provider.factory";
type ActiveUserStateProviderFactory = FactoryOptions;
export type ActiveUserStateProviderInitOptions = ActiveUserStateProviderFactory &
AccountServiceInitOptions &
SingleUserStateProviderInitOptions;
export async function activeUserStateProviderFactory(
cache: { activeUserStateProvider?: ActiveUserStateProvider } & CachedServices,
opts: ActiveUserStateProviderInitOptions,
): Promise<ActiveUserStateProvider> {
return factory(
cache,
"activeUserStateProvider",
opts,
async () =>
new DefaultActiveUserStateProvider(
await accountServiceFactory(cache, opts),
await singleUserStateProviderFactory(cache, opts),
),
);
}