2022-08-29 20:46:42 +02:00
|
|
|
import { CipherService as AbstractCipherService } from "@bitwarden/common/abstractions/cipher.service";
|
|
|
|
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
|
|
|
import { CipherService } from "@bitwarden/common/services/cipher.service";
|
|
|
|
|
|
|
|
import { apiServiceFactory, ApiServiceInitOptions } from "./api-service.factory";
|
|
|
|
import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory";
|
2022-10-27 23:38:54 +02:00
|
|
|
import { encryptServiceFactory, EncryptServiceInitOptions } from "./encrypt-service.factory";
|
2022-08-29 20:46:42 +02:00
|
|
|
import { CachedServices, factory, FactoryOptions } from "./factory-options";
|
|
|
|
import {
|
|
|
|
FileUploadServiceInitOptions,
|
|
|
|
fileUploadServiceFactory,
|
|
|
|
} from "./file-upload-service.factory";
|
|
|
|
import { i18nServiceFactory, I18nServiceInitOptions } from "./i18n-service.factory";
|
|
|
|
import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory";
|
|
|
|
import { SettingsServiceInitOptions, settingsServiceFactory } from "./settings-service.factory";
|
|
|
|
import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory";
|
|
|
|
|
|
|
|
type CipherServiceFactoryOptions = FactoryOptions & {
|
|
|
|
cipherServiceOptions?: {
|
|
|
|
searchServiceFactory?: () => SearchService;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CipherServiceInitOptions = CipherServiceFactoryOptions &
|
|
|
|
CryptoServiceInitOptions &
|
|
|
|
SettingsServiceInitOptions &
|
|
|
|
ApiServiceInitOptions &
|
|
|
|
FileUploadServiceInitOptions &
|
|
|
|
I18nServiceInitOptions &
|
|
|
|
LogServiceInitOptions &
|
2022-10-27 23:38:54 +02:00
|
|
|
StateServiceInitOptions &
|
|
|
|
EncryptServiceInitOptions;
|
2022-08-29 20:46:42 +02:00
|
|
|
|
|
|
|
export function cipherServiceFactory(
|
|
|
|
cache: { cipherService?: AbstractCipherService } & CachedServices,
|
|
|
|
opts: CipherServiceInitOptions
|
|
|
|
): Promise<AbstractCipherService> {
|
|
|
|
return factory(
|
|
|
|
cache,
|
|
|
|
"cipherService",
|
|
|
|
opts,
|
|
|
|
async () =>
|
|
|
|
new CipherService(
|
|
|
|
await cryptoServiceFactory(cache, opts),
|
|
|
|
await settingsServiceFactory(cache, opts),
|
|
|
|
await apiServiceFactory(cache, opts),
|
|
|
|
await fileUploadServiceFactory(cache, opts),
|
|
|
|
await i18nServiceFactory(cache, opts),
|
2022-10-11 18:24:33 +02:00
|
|
|
opts.cipherServiceOptions?.searchServiceFactory === undefined
|
2022-08-29 20:46:42 +02:00
|
|
|
? () => cache.searchService
|
|
|
|
: opts.cipherServiceOptions.searchServiceFactory,
|
|
|
|
await logServiceFactory(cache, opts),
|
2022-10-27 23:38:54 +02:00
|
|
|
await stateServiceFactory(cache, opts),
|
|
|
|
await encryptServiceFactory(cache, opts)
|
2022-08-29 20:46:42 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|