1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

Add missing state provider factories (#7262)

This commit is contained in:
Matt Gibson 2023-12-18 07:39:05 -05:00 committed by GitHub
parent 6199e58532
commit bc1f93d098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,43 @@
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 { EncryptServiceInitOptions, encryptServiceFactory } from "./encrypt-service.factory";
import { CachedServices, FactoryOptions, factory } from "./factory-options";
import {
DiskStorageServiceInitOptions,
MemoryStorageServiceInitOptions,
observableDiskStorageServiceFactory,
observableMemoryStorageServiceFactory,
} from "./storage-service.factory";
type ActiveUserStateProviderFactory = FactoryOptions;
export type ActiveUserStateProviderInitOptions = ActiveUserStateProviderFactory &
AccountServiceInitOptions &
EncryptServiceInitOptions &
MemoryStorageServiceInitOptions &
DiskStorageServiceInitOptions;
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 encryptServiceFactory(cache, opts),
await observableMemoryStorageServiceFactory(cache, opts),
await observableDiskStorageServiceFactory(cache, opts),
),
);
}

View File

@ -0,0 +1,36 @@
import { SingleUserStateProvider } 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 { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-single-user-state.provider";
import { EncryptServiceInitOptions, encryptServiceFactory } from "./encrypt-service.factory";
import { CachedServices, FactoryOptions, factory } from "./factory-options";
import {
DiskStorageServiceInitOptions,
MemoryStorageServiceInitOptions,
observableDiskStorageServiceFactory,
observableMemoryStorageServiceFactory,
} from "./storage-service.factory";
type SingleUserStateProviderFactoryOptions = FactoryOptions;
export type SingleUserStateProviderInitOptions = SingleUserStateProviderFactoryOptions &
EncryptServiceInitOptions &
MemoryStorageServiceInitOptions &
DiskStorageServiceInitOptions;
export async function singleUserStateProviderFactory(
cache: { singleUserStateProvider?: SingleUserStateProvider } & CachedServices,
opts: SingleUserStateProviderInitOptions,
): Promise<SingleUserStateProvider> {
return factory(
cache,
"singleUserStateProvider",
opts,
async () =>
new DefaultSingleUserStateProvider(
await encryptServiceFactory(cache, opts),
await observableMemoryStorageServiceFactory(cache, opts),
await observableDiskStorageServiceFactory(cache, opts),
),
);
}

View File

@ -0,0 +1,41 @@
import { StateProvider } 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 { DefaultStateProvider } from "@bitwarden/common/platform/state/implementations/default-state.provider";
import {
ActiveUserStateProviderInitOptions,
activeUserStateProviderFactory,
} from "./active-user-state-provider.factory";
import { CachedServices, FactoryOptions, factory } from "./factory-options";
import {
GlobalStateProviderInitOptions,
globalStateProviderFactory,
} from "./global-state-provider.factory";
import {
SingleUserStateProviderInitOptions,
singleUserStateProviderFactory,
} from "./single-user-state-provider.factory";
type StateProviderFactoryOptions = FactoryOptions;
export type StateProviderInitOptions = StateProviderFactoryOptions &
GlobalStateProviderInitOptions &
ActiveUserStateProviderInitOptions &
SingleUserStateProviderInitOptions;
export async function stateProviderFactory(
cache: { stateProvider?: StateProvider } & CachedServices,
opts: StateProviderInitOptions,
): Promise<StateProvider> {
return factory(
cache,
"stateProvider",
opts,
async () =>
new DefaultStateProvider(
await activeUserStateProviderFactory(cache, opts),
await singleUserStateProviderFactory(cache, opts),
await globalStateProviderFactory(cache, opts),
),
);
}