2022-08-29 20:46:42 +02:00
|
|
|
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CipherService as AbstractCipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
|
|
|
import { CipherService } from "@bitwarden/common/vault/services/cipher.service";
|
2022-08-29 20:46:42 +02:00
|
|
|
|
2023-01-31 22:08:37 +01:00
|
|
|
import {
|
|
|
|
apiServiceFactory,
|
|
|
|
ApiServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/api-service.factory";
|
|
|
|
import {
|
|
|
|
cryptoServiceFactory,
|
|
|
|
CryptoServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/crypto-service.factory";
|
|
|
|
import {
|
|
|
|
encryptServiceFactory,
|
|
|
|
EncryptServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/encrypt-service.factory";
|
|
|
|
import {
|
|
|
|
CachedServices,
|
|
|
|
factory,
|
|
|
|
FactoryOptions,
|
|
|
|
} from "../../../background/service_factories/factory-options";
|
2022-08-29 20:46:42 +02:00
|
|
|
import {
|
|
|
|
FileUploadServiceInitOptions,
|
|
|
|
fileUploadServiceFactory,
|
2023-01-31 22:08:37 +01:00
|
|
|
} from "../../../background/service_factories/file-upload-service.factory";
|
|
|
|
import {
|
|
|
|
i18nServiceFactory,
|
|
|
|
I18nServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/i18n-service.factory";
|
|
|
|
import {
|
|
|
|
logServiceFactory,
|
|
|
|
LogServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/log-service.factory";
|
|
|
|
import {
|
|
|
|
SettingsServiceInitOptions,
|
|
|
|
settingsServiceFactory,
|
|
|
|
} from "../../../background/service_factories/settings-service.factory";
|
|
|
|
import {
|
|
|
|
stateServiceFactory,
|
|
|
|
StateServiceInitOptions,
|
|
|
|
} from "../../../background/service_factories/state-service.factory";
|
2022-08-29 20:46:42 +02:00
|
|
|
|
|
|
|
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
|
2023-01-07 01:31:32 +01:00
|
|
|
? () => cache.searchService as SearchService
|
2022-08-29 20:46:42 +02:00
|
|
|
: 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
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|