diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 41e0d07275c..fdd6b70a9a1 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -27,11 +27,6 @@ ## Before you submit - - -``` -- [ ] I have checked for **linting** errors (`npm run lint`) (required) -- [ ] I have added **unit tests** where it makes sense to do so (encouraged but not required) -- [ ] This change requires a **documentation update** (notify the documentation team) -- [ ] This change has particular **deployment requirements** (notify the DevOps team) -``` +- Please add **unit tests** where it makes sense to do so (encouraged but not required) +- If this change requires a **documentation update** - notify the documentation team +- If this change has particular **deployment requirements** - notify the DevOps team diff --git a/apps/browser/src/background/commands.background.ts b/apps/browser/src/background/commands.background.ts index 4d85c91c0bc..05a83c8eb54 100644 --- a/apps/browser/src/background/commands.background.ts +++ b/apps/browser/src/background/commands.background.ts @@ -1,7 +1,7 @@ import { AuthService } from "@bitwarden/common/abstractions/auth.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { BrowserApi } from "../browser/browserApi"; diff --git a/apps/browser/src/background/idle.background.ts b/apps/browser/src/background/idle.background.ts index aecadd31fc3..56e2e2dd7e1 100644 --- a/apps/browser/src/background/idle.background.ts +++ b/apps/browser/src/background/idle.background.ts @@ -1,5 +1,5 @@ import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { StateService } from "../services/abstractions/state.service"; diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index e771740e91a..cab48c0bc59 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -26,7 +26,7 @@ import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abs import { SendService as SendServiceAbstraction } from "@bitwarden/common/abstractions/send.service"; import { SettingsService as SettingsServiceAbstraction } from "@bitwarden/common/abstractions/settings.service"; import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; -import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/abstractions/system.service"; import { TokenService as TokenServiceAbstraction } from "@bitwarden/common/abstractions/token.service"; import { TotpService as TotpServiceAbstraction } from "@bitwarden/common/abstractions/totp.service"; @@ -34,7 +34,8 @@ import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/comm import { UserVerificationApiServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification-api.service.abstraction"; import { UserVerificationService as UserVerificationServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { UsernameGenerationService as UsernameGenerationServiceAbstraction } from "@bitwarden/common/abstractions/usernameGeneration.service"; -import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { CipherRepromptType } from "@bitwarden/common/enums/cipherRepromptType"; import { CipherType } from "@bitwarden/common/enums/cipherType"; @@ -47,6 +48,7 @@ import { AuditService } from "@bitwarden/common/services/audit.service"; import { AuthService } from "@bitwarden/common/services/auth.service"; import { CipherService } from "@bitwarden/common/services/cipher.service"; import { CollectionService } from "@bitwarden/common/services/collection.service"; +import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service"; import { ContainerService } from "@bitwarden/common/services/container.service"; import { EncryptService } from "@bitwarden/common/services/encrypt.service"; import { EventService } from "@bitwarden/common/services/event.service"; @@ -54,6 +56,7 @@ import { ExportService } from "@bitwarden/common/services/export.service"; import { FileUploadService } from "@bitwarden/common/services/fileUpload.service"; import { FolderApiService } from "@bitwarden/common/services/folder/folder-api.service"; import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service"; +import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service"; import { NotificationsService } from "@bitwarden/common/services/notifications.service"; import { OrganizationService } from "@bitwarden/common/services/organization.service"; import { PasswordGenerationService } from "@bitwarden/common/services/passwordGeneration.service"; @@ -64,7 +67,7 @@ import { SearchService } from "@bitwarden/common/services/search.service"; import { SendService } from "@bitwarden/common/services/send.service"; import { SettingsService } from "@bitwarden/common/services/settings.service"; import { StateMigrationService } from "@bitwarden/common/services/stateMigration.service"; -import { SyncService } from "@bitwarden/common/services/sync.service"; +import { SyncService } from "@bitwarden/common/services/sync/sync.service"; import { SystemService } from "@bitwarden/common/services/system.service"; import { TokenService } from "@bitwarden/common/services/token.service"; import { TotpService } from "@bitwarden/common/services/totp.service"; @@ -72,6 +75,8 @@ import { TwoFactorService } from "@bitwarden/common/services/twoFactor.service"; import { UserVerificationApiService } from "@bitwarden/common/services/userVerification/userVerification-api.service"; import { UserVerificationService } from "@bitwarden/common/services/userVerification/userVerification.service"; import { UsernameGenerationService } from "@bitwarden/common/services/usernameGeneration.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vaultTimeout/vaultTimeoutSettings.service"; +import { WebCryptoFunctionService } from "@bitwarden/common/services/webCryptoFunction.service"; import { BrowserApi } from "../browser/browserApi"; import { SafariApp } from "../browser/safariApp"; @@ -82,13 +87,17 @@ import { StateService as StateServiceAbstraction } from "../services/abstraction import AutofillService from "../services/autofill.service"; import { BrowserEnvironmentService } from "../services/browser-environment.service"; import { BrowserCryptoService } from "../services/browserCrypto.service"; +import BrowserLocalStorageService from "../services/browserLocalStorage.service"; import BrowserMessagingService from "../services/browserMessaging.service"; import BrowserMessagingPrivateModeBackgroundService from "../services/browserMessagingPrivateModeBackground.service"; import BrowserPlatformUtilsService from "../services/browserPlatformUtils.service"; import { FolderService } from "../services/folders/folder.service"; import I18nService from "../services/i18n.service"; +import { KeyGenerationService } from "../services/keyGeneration.service"; +import { LocalBackedSessionStorageService } from "../services/localBackedSessionStorage.service"; +import { StateService } from "../services/state.service"; import { VaultFilterService } from "../services/vaultFilter.service"; -import VaultTimeoutService from "../services/vaultTimeout.service"; +import VaultTimeoutService from "../services/vaultTimeout/vaultTimeout.service"; import CommandsBackground from "./commands.background"; import ContextMenusBackground from "./contextMenus.background"; @@ -97,17 +106,6 @@ import IconDetails from "./models/iconDetails"; import { NativeMessagingBackground } from "./nativeMessaging.background"; import NotificationBackground from "./notification.background"; import RuntimeBackground from "./runtime.background"; -import { cryptoFunctionServiceFactory } from "./service_factories/crypto-function-service.factory"; -import { encryptServiceFactory } from "./service_factories/encrypt-service.factory"; -import { environmentServiceFactory } from "./service_factories/environment-service.factory"; -import { logServiceFactory } from "./service_factories/log-service.factory"; -import { stateMigrationServiceFactory } from "./service_factories/state-migration-service.factory"; -import { stateServiceFactory } from "./service_factories/state-service.factory"; -import { - diskStorageServiceFactory, - memoryStorageServiceFactory, - secureStorageServiceFactory, -} from "./service_factories/storage-service.factory"; import TabsBackground from "./tabs.background"; import WebRequestBackground from "./webRequest.background"; @@ -130,6 +128,7 @@ export default class MainBackground { folderService: InternalFolderServiceAbstraction; collectionService: CollectionServiceAbstraction; vaultTimeoutService: VaultTimeoutServiceAbstraction; + vaultTimeoutSettingsService: VaultTimeoutSettingsServiceAbstraction; syncService: SyncServiceAbstraction; passwordGenerationService: PasswordGenerationServiceAbstraction; totpService: TotpServiceAbstraction; @@ -199,40 +198,33 @@ export default class MainBackground { const logoutCallback = async (expired: boolean, userId?: string) => await this.logout(expired, userId); - const services: Record = {}; - const factoryOptions = { - logServiceOptions: { - isDev: false, - }, - cryptoFunctionServiceOptions: { - win: window, - }, - stateMigrationServiceOptions: { - stateFactory: new StateFactory(GlobalState, Account), - }, - stateServiceOptions: { - stateFactory: new StateFactory(GlobalState, Account), - }, - }; - this.messagingService = isPrivateMode ? new BrowserMessagingPrivateModeBackgroundService() : new BrowserMessagingService(); - this.logService = logServiceFactory(services, factoryOptions); - this.cryptoFunctionService = cryptoFunctionServiceFactory(services, factoryOptions); - this.storageService = diskStorageServiceFactory(services, factoryOptions); - this.secureStorageService = secureStorageServiceFactory(services, factoryOptions); - this.memoryStorageService = memoryStorageServiceFactory(services, { - ...factoryOptions, - encryptServiceOptions: { - logMacFailures: false, - }, - }); - this.stateMigrationService = stateMigrationServiceFactory(services, factoryOptions); - this.stateService = stateServiceFactory(services, { - ...factoryOptions, - encryptServiceOptions: { logMacFailures: false }, - }); + this.logService = new ConsoleLogService(false); + this.cryptoFunctionService = new WebCryptoFunctionService(window); + this.storageService = new BrowserLocalStorageService(); + this.secureStorageService = new BrowserLocalStorageService(); + this.memoryStorageService = + chrome.runtime.getManifest().manifest_version == 3 + ? new LocalBackedSessionStorageService( + new EncryptService(this.cryptoFunctionService, this.logService, false), + new KeyGenerationService(this.cryptoFunctionService) + ) + : new MemoryStorageService(); + this.stateMigrationService = new StateMigrationService( + this.storageService, + this.secureStorageService, + new StateFactory(GlobalState, Account) + ); + this.stateService = new StateService( + this.storageService, + this.secureStorageService, + this.memoryStorageService, + this.logService, + this.stateMigrationService, + new StateFactory(GlobalState, Account) + ); this.platformUtilsService = new BrowserPlatformUtilsService( this.messagingService, (clipboardValue, clearMs) => { @@ -255,13 +247,7 @@ export default class MainBackground { } ); this.i18nService = new I18nService(BrowserApi.getUILanguage(window)); - this.encryptService = encryptServiceFactory(services, { - ...factoryOptions, - encryptServiceOptions: { - logMacFailures: true, - }, - alwaysInitializeNewService: true, - }); // Update encrypt service with new instances + this.encryptService = new EncryptService(this.cryptoFunctionService, this.logService, true); this.cryptoService = new BrowserCryptoService( this.cryptoFunctionService, this.encryptService, @@ -271,12 +257,7 @@ export default class MainBackground { ); this.tokenService = new TokenService(this.stateService); this.appIdService = new AppIdService(this.storageService); - this.environmentService = environmentServiceFactory(services, { - ...factoryOptions, - encryptServiceOptions: { - logMacFailures: false, - }, - }); + this.environmentService = new BrowserEnvironmentService(this.stateService, this.logService); this.apiService = new ApiService( this.tokenService, this.platformUtilsService, @@ -370,6 +351,13 @@ export default class MainBackground { this.i18nService ); + this.vaultTimeoutSettingsService = new VaultTimeoutSettingsService( + this.cryptoService, + this.tokenService, + this.policyService, + this.stateService + ); + this.vaultTimeoutService = new VaultTimeoutService( this.cipherService, this.folderService, @@ -378,14 +366,14 @@ export default class MainBackground { this.platformUtilsService, this.messagingService, this.searchService, - this.tokenService, - this.policyService, this.keyConnectorService, this.stateService, this.authService, + this.vaultTimeoutSettingsService, lockedCallback, logoutCallback ); + this.providerService = new ProviderService(this.stateService); this.syncService = new SyncService( this.apiService, @@ -647,7 +635,7 @@ export default class MainBackground { this.collectionService.clear(userId), this.policyService.clear(userId), this.passwordGenerationService.clear(userId), - this.vaultTimeoutService.clear(userId), + this.vaultTimeoutSettingsService.clear(userId), this.keyConnectorService.clear(), this.vaultFilterService.clear(), ]); diff --git a/apps/browser/src/background/service_factories/api-service.factory.ts b/apps/browser/src/background/service_factories/api-service.factory.ts new file mode 100644 index 00000000000..cee76c4e1d6 --- /dev/null +++ b/apps/browser/src/background/service_factories/api-service.factory.ts @@ -0,0 +1,47 @@ +import { ApiService as AbstractApiService } from "@bitwarden/common/abstractions/api.service"; +import { ApiService } from "@bitwarden/common/services/api.service"; + +import { AppIdServiceInitOptions, appIdServiceFactory } from "./app-id-service.factory"; +import { + environmentServiceFactory, + EnvironmentServiceInitOptions, +} from "./environment-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { + PlatformUtilsServiceInitOptions, + platformUtilsServiceFactory, +} from "./platform-utils-service.factory"; +import { TokenServiceInitOptions, tokenServiceFactory } from "./token-service.factory"; + +type ApiServiceFactoryOptions = FactoryOptions & { + apiServiceOptions: { + logoutCallback: (expired: boolean) => Promise; + customUserAgent?: string; + }; +}; + +export type ApiServiceInitOptions = ApiServiceFactoryOptions & + TokenServiceInitOptions & + PlatformUtilsServiceInitOptions & + EnvironmentServiceInitOptions & + AppIdServiceInitOptions; + +export function apiServiceFactory( + cache: { apiService?: AbstractApiService } & CachedServices, + opts: ApiServiceInitOptions +): Promise { + return factory( + cache, + "apiService", + opts, + async () => + new ApiService( + await tokenServiceFactory(cache, opts), + await platformUtilsServiceFactory(cache, opts), + await environmentServiceFactory(cache, opts), + await appIdServiceFactory(cache, opts), + opts.apiServiceOptions.logoutCallback, + opts.apiServiceOptions.customUserAgent + ) + ); +} diff --git a/apps/browser/src/background/service_factories/app-id-service.factory.ts b/apps/browser/src/background/service_factories/app-id-service.factory.ts new file mode 100644 index 00000000000..743c8eb5bc6 --- /dev/null +++ b/apps/browser/src/background/service_factories/app-id-service.factory.ts @@ -0,0 +1,23 @@ +import { DiskStorageOptions } from "@koa/multer"; + +import { AppIdService as AbstractAppIdService } from "@bitwarden/common/abstractions/appId.service"; +import { AppIdService } from "@bitwarden/common/services/appId.service"; + +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { diskStorageServiceFactory } from "./storage-service.factory"; + +type AppIdServiceFactoryOptions = FactoryOptions; + +export type AppIdServiceInitOptions = AppIdServiceFactoryOptions & DiskStorageOptions; + +export function appIdServiceFactory( + cache: { appIdService?: AbstractAppIdService } & CachedServices, + opts: AppIdServiceInitOptions +): Promise { + return factory( + cache, + "appIdService", + opts, + async () => new AppIdService(await diskStorageServiceFactory(cache, opts)) + ); +} diff --git a/apps/browser/src/background/service_factories/auth-service.factory.ts b/apps/browser/src/background/service_factories/auth-service.factory.ts new file mode 100644 index 00000000000..6f4fb322b00 --- /dev/null +++ b/apps/browser/src/background/service_factories/auth-service.factory.ts @@ -0,0 +1,66 @@ +import { AuthService as AbstractAuthService } from "@bitwarden/common/abstractions/auth.service"; +import { AuthService } from "@bitwarden/common/services/auth.service"; + +import { apiServiceFactory, ApiServiceInitOptions } from "./api-service.factory"; +import { appIdServiceFactory } from "./app-id-service.factory"; +import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory"; +import { + environmentServiceFactory, + EnvironmentServiceInitOptions, +} from "./environment-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { I18nServiceInitOptions, i18nServiceFactory } from "./i18n-service.factory"; +import { + KeyConnectorServiceInitOptions, + keyConnectorServiceFactory, +} from "./key-connector-service.factory"; +import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; +import { MessagingServiceInitOptions, messagingServiceFactory } from "./messaging-service.factory"; +import { + PlatformUtilsServiceInitOptions, + platformUtilsServiceFactory, +} from "./platform-utils-service.factory"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; +import { TokenServiceInitOptions, tokenServiceFactory } from "./token-service.factory"; +import { TwoFactorServiceInitOptions, twoFactorServiceFactory } from "./two-factor-service.factory"; + +type AuthServiceFactoyOptions = FactoryOptions; + +export type AuthServiceInitOptions = AuthServiceFactoyOptions & + CryptoServiceInitOptions & + ApiServiceInitOptions & + TokenServiceInitOptions & + PlatformUtilsServiceInitOptions & + MessagingServiceInitOptions & + LogServiceInitOptions & + KeyConnectorServiceInitOptions & + EnvironmentServiceInitOptions & + StateServiceInitOptions & + TwoFactorServiceInitOptions & + I18nServiceInitOptions; + +export function authServiceFactory( + cache: { authService?: AbstractAuthService } & CachedServices, + opts: AuthServiceInitOptions +): Promise { + return factory( + cache, + "authService", + opts, + async () => + new AuthService( + await cryptoServiceFactory(cache, opts), + await apiServiceFactory(cache, opts), + await tokenServiceFactory(cache, opts), + await appIdServiceFactory(cache, opts), + await platformUtilsServiceFactory(cache, opts), + await messagingServiceFactory(cache, opts), + await logServiceFactory(cache, opts), + await keyConnectorServiceFactory(cache, opts), + await environmentServiceFactory(cache, opts), + await stateServiceFactory(cache, opts), + await twoFactorServiceFactory(cache, opts), + await i18nServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/cipher-service.factory.ts b/apps/browser/src/background/service_factories/cipher-service.factory.ts new file mode 100644 index 00000000000..149ac54fc82 --- /dev/null +++ b/apps/browser/src/background/service_factories/cipher-service.factory.ts @@ -0,0 +1,54 @@ +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"; +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 & + StateServiceInitOptions; + +export function cipherServiceFactory( + cache: { cipherService?: AbstractCipherService } & CachedServices, + opts: CipherServiceInitOptions +): Promise { + 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), + opts.cipherServiceOptions.searchServiceFactory === undefined + ? () => cache.searchService + : opts.cipherServiceOptions.searchServiceFactory, + await logServiceFactory(cache, opts), + await stateServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/collection-service.factory.ts b/apps/browser/src/background/service_factories/collection-service.factory.ts new file mode 100644 index 00000000000..d85e6dd8dcd --- /dev/null +++ b/apps/browser/src/background/service_factories/collection-service.factory.ts @@ -0,0 +1,34 @@ +import { CollectionService as AbstractCollectionService } from "@bitwarden/common/abstractions/collection.service"; +import { CollectionService } from "@bitwarden/common/services/collection.service"; + +import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { i18nServiceFactory, I18nServiceInitOptions } from "./i18n-service.factory"; +import { + stateServiceFactory as stateServiceFactory, + StateServiceInitOptions, +} from "./state-service.factory"; + +type CollectionServiceFactoryOptions = FactoryOptions; + +export type CollectionServiceInitOptions = CollectionServiceFactoryOptions & + CryptoServiceInitOptions & + I18nServiceInitOptions & + StateServiceInitOptions; + +export function collectionServiceFactory( + cache: { collectionService?: AbstractCollectionService } & CachedServices, + opts: CollectionServiceInitOptions +): Promise { + return factory( + cache, + "collectionService", + opts, + async () => + new CollectionService( + await cryptoServiceFactory(cache, opts), + await i18nServiceFactory(cache, opts), + await stateServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/crypto-function-service.factory.ts b/apps/browser/src/background/service_factories/crypto-function-service.factory.ts index fa0fd5d9a03..d7611c86a1f 100644 --- a/apps/browser/src/background/service_factories/crypto-function-service.factory.ts +++ b/apps/browser/src/background/service_factories/crypto-function-service.factory.ts @@ -14,7 +14,7 @@ export type CryptoFunctionServiceInitOptions = CryptoFunctionServiceFactoryOptio export function cryptoFunctionServiceFactory( cache: { cryptoFunctionService?: CryptoFunctionService } & CachedServices, opts: CryptoFunctionServiceFactoryOptions -): CryptoFunctionService { +): Promise { return factory( cache, "cryptoFunctionService", diff --git a/apps/browser/src/background/service_factories/crypto-service.factory.ts b/apps/browser/src/background/service_factories/crypto-service.factory.ts new file mode 100644 index 00000000000..b61b72ec04b --- /dev/null +++ b/apps/browser/src/background/service_factories/crypto-service.factory.ts @@ -0,0 +1,43 @@ +import { CryptoService as AbstractCryptoService } from "@bitwarden/common/abstractions/crypto.service"; +import { CryptoService } from "@bitwarden/common/services/crypto.service"; + +import { + cryptoFunctionServiceFactory, + CryptoFunctionServiceInitOptions, +} from "./crypto-function-service.factory"; +import { encryptServiceFactory, EncryptServiceInitOptions } from "./encrypt-service.factory"; +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; +import { + platformUtilsServiceFactory, + PlatformUtilsServiceInitOptions, +} from "./platform-utils-service.factory"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; + +type CryptoServiceFactoryOptions = FactoryOptions; + +export type CryptoServiceInitOptions = CryptoServiceFactoryOptions & + CryptoFunctionServiceInitOptions & + EncryptServiceInitOptions & + PlatformUtilsServiceInitOptions & + LogServiceInitOptions & + StateServiceInitOptions; + +export function cryptoServiceFactory( + cache: { cryptoService?: AbstractCryptoService } & CachedServices, + opts: CryptoServiceInitOptions +): Promise { + return factory( + cache, + "cryptoService", + opts, + async () => + new CryptoService( + await cryptoFunctionServiceFactory(cache, opts), + await encryptServiceFactory(cache, opts), + await platformUtilsServiceFactory(cache, opts), + await logServiceFactory(cache, opts), + await stateServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/encrypt-service.factory.ts b/apps/browser/src/background/service_factories/encrypt-service.factory.ts index c8f529b0ecb..fffc9f9d296 100644 --- a/apps/browser/src/background/service_factories/encrypt-service.factory.ts +++ b/apps/browser/src/background/service_factories/encrypt-service.factory.ts @@ -20,15 +20,15 @@ export type EncryptServiceInitOptions = EncryptServiceFactoryOptions & export function encryptServiceFactory( cache: { encryptService?: EncryptService } & CachedServices, opts: EncryptServiceInitOptions -): EncryptService { +): Promise { return factory( cache, "encryptService", opts, - () => + async () => new EncryptService( - cryptoFunctionServiceFactory(cache, opts), - logServiceFactory(cache, opts), + await cryptoFunctionServiceFactory(cache, opts), + await logServiceFactory(cache, opts), opts.encryptServiceOptions.logMacFailures ) ); diff --git a/apps/browser/src/background/service_factories/environment-service.factory.ts b/apps/browser/src/background/service_factories/environment-service.factory.ts index 4116583970f..5150c7bd4a0 100644 --- a/apps/browser/src/background/service_factories/environment-service.factory.ts +++ b/apps/browser/src/background/service_factories/environment-service.factory.ts @@ -16,15 +16,15 @@ export type EnvironmentServiceInitOptions = EnvironmentServiceFactoryOptions & export function environmentServiceFactory( cache: { environmentService?: BrowserEnvironmentService } & CachedServices, opts: EnvironmentServiceInitOptions -): BrowserEnvironmentService { +): Promise { return factory( cache, "environmentService", opts, - () => + async () => new BrowserEnvironmentService( - stateServiceFactory(cache, opts), - logServiceFactory(cache, opts) + await stateServiceFactory(cache, opts), + await logServiceFactory(cache, opts) ) ); } diff --git a/apps/browser/src/background/service_factories/factory-options.ts b/apps/browser/src/background/service_factories/factory-options.ts index a78d607854a..12129e4e673 100644 --- a/apps/browser/src/background/service_factories/factory-options.ts +++ b/apps/browser/src/background/service_factories/factory-options.ts @@ -6,14 +6,20 @@ export type FactoryOptions = { [optionsKey: string]: unknown; }; -export function factory< +export async function factory< TCache extends CachedServices, TName extends keyof TCache, TOpts extends FactoryOptions ->(cachedServices: TCache, name: TName, opts: TOpts, factory: () => TCache[TName]): TCache[TName] { +>( + cachedServices: TCache, + name: TName, + opts: TOpts, + factory: () => TCache[TName] | Promise +): Promise { let instance = cachedServices[name]; if (opts.alwaysInitializeNewService || !instance) { - instance = factory(); + const instanceOrPromise = factory(); + instance = instanceOrPromise instanceof Promise ? await instanceOrPromise : instanceOrPromise; } if (!opts.doNotStoreInitializedService) { diff --git a/apps/browser/src/background/service_factories/file-upload-service.factory.ts b/apps/browser/src/background/service_factories/file-upload-service.factory.ts new file mode 100644 index 00000000000..0aa04126d92 --- /dev/null +++ b/apps/browser/src/background/service_factories/file-upload-service.factory.ts @@ -0,0 +1,28 @@ +import { FileUploadService as AbstractFileUploadService } from "@bitwarden/common/abstractions/fileUpload.service"; +import { FileUploadService } from "@bitwarden/common/services/fileUpload.service"; + +import { apiServiceFactory, ApiServiceInitOptions } from "./api-service.factory"; +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; + +type FileUploadServiceFactoyOptions = FactoryOptions; + +export type FileUploadServiceInitOptions = FileUploadServiceFactoyOptions & + LogServiceInitOptions & + ApiServiceInitOptions; + +export function fileUploadServiceFactory( + cache: { fileUploadService?: AbstractFileUploadService } & CachedServices, + opts: FileUploadServiceInitOptions +): Promise { + return factory( + cache, + "fileUploadService", + opts, + async () => + new FileUploadService( + await logServiceFactory(cache, opts), + await apiServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/folder-service.factory.ts b/apps/browser/src/background/service_factories/folder-service.factory.ts new file mode 100644 index 00000000000..a7c90d234b1 --- /dev/null +++ b/apps/browser/src/background/service_factories/folder-service.factory.ts @@ -0,0 +1,38 @@ +import { FolderService as AbstractFolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; + +import { FolderService } from "../../services/folders/folder.service"; + +import { cipherServiceFactory, CipherServiceInitOptions } from "./cipher-service.factory"; +import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { i18nServiceFactory, I18nServiceInitOptions } from "./i18n-service.factory"; +import { + stateServiceFactory as stateServiceFactory, + StateServiceInitOptions, +} from "./state-service.factory"; + +type FolderServiceFactoryOptions = FactoryOptions; + +export type FolderServiceInitOptions = FolderServiceFactoryOptions & + CryptoServiceInitOptions & + CipherServiceInitOptions & + I18nServiceInitOptions & + StateServiceInitOptions; + +export function folderServiceFactory( + cache: { folderService?: AbstractFolderService } & CachedServices, + opts: FolderServiceInitOptions +): Promise { + return factory( + cache, + "folderService", + opts, + async () => + new FolderService( + await cryptoServiceFactory(cache, opts), + await i18nServiceFactory(cache, opts), + await cipherServiceFactory(cache, opts), + await stateServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/i18n-service.factory.ts b/apps/browser/src/background/service_factories/i18n-service.factory.ts new file mode 100644 index 00000000000..1ba61d70b34 --- /dev/null +++ b/apps/browser/src/background/service_factories/i18n-service.factory.ts @@ -0,0 +1,30 @@ +import { I18nService as AbstractI18nService } from "@bitwarden/common/abstractions/i18n.service"; +import { I18nService as BaseI18nService } from "@bitwarden/common/services/i18n.service"; + +import I18nService from "../../services/i18n.service"; + +import { FactoryOptions, CachedServices, factory } from "./factory-options"; + +type I18nServiceFactoryOptions = FactoryOptions & { + i18nServiceOptions: { + systemLanguage: string; + }; +}; + +export type I18nServiceInitOptions = I18nServiceFactoryOptions; + +export async function i18nServiceFactory( + cache: { i18nService?: AbstractI18nService } & CachedServices, + opts: I18nServiceInitOptions +): Promise { + const service = await factory( + cache, + "i18nService", + opts, + () => new I18nService(opts.i18nServiceOptions.systemLanguage) + ); + if (!(service as BaseI18nService as any).inited) { + await (service as BaseI18nService).init(); + } + return service; +} diff --git a/apps/browser/src/background/service_factories/key-connector-service.factory.ts b/apps/browser/src/background/service_factories/key-connector-service.factory.ts new file mode 100644 index 00000000000..80a0df6a0a8 --- /dev/null +++ b/apps/browser/src/background/service_factories/key-connector-service.factory.ts @@ -0,0 +1,54 @@ +import { KeyConnectorService as AbstractKeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service"; +import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service"; + +import { apiServiceFactory, ApiServiceInitOptions } from "./api-service.factory"; +import { + cryptoFunctionServiceFactory, + CryptoFunctionServiceInitOptions, +} from "./crypto-function-service.factory"; +import { CryptoServiceInitOptions, cryptoServiceFactory } from "./crypto-service.factory"; +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; +import { + OrganizationServiceInitOptions, + organizationServiceFactory, +} from "./organization-service.factory"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; +import { tokenServiceFactory, TokenServiceInitOptions } from "./token-service.factory"; + +type KeyConnectorServiceFactoryOptions = FactoryOptions & { + keyConnectorServiceOptions: { + logoutCallback: (expired: boolean, userId?: string) => Promise; + }; +}; + +export type KeyConnectorServiceInitOptions = KeyConnectorServiceFactoryOptions & + StateServiceInitOptions & + CryptoServiceInitOptions & + ApiServiceInitOptions & + TokenServiceInitOptions & + LogServiceInitOptions & + OrganizationServiceInitOptions & + CryptoFunctionServiceInitOptions; + +export function keyConnectorServiceFactory( + cache: { keyConnectorService?: AbstractKeyConnectorService } & CachedServices, + opts: KeyConnectorServiceInitOptions +): Promise { + return factory( + cache, + "keyConnectorService", + opts, + async () => + new KeyConnectorService( + await stateServiceFactory(cache, opts), + await cryptoServiceFactory(cache, opts), + await apiServiceFactory(cache, opts), + await tokenServiceFactory(cache, opts), + await logServiceFactory(cache, opts), + await organizationServiceFactory(cache, opts), + await cryptoFunctionServiceFactory(cache, opts), + opts.keyConnectorServiceOptions.logoutCallback + ) + ); +} diff --git a/apps/browser/src/background/service_factories/key-generation-service.factory.ts b/apps/browser/src/background/service_factories/key-generation-service.factory.ts index 89fe5f3066e..d6d31b6326e 100644 --- a/apps/browser/src/background/service_factories/key-generation-service.factory.ts +++ b/apps/browser/src/background/service_factories/key-generation-service.factory.ts @@ -14,11 +14,11 @@ export type KeyGenerationServiceInitOptions = KeyGenerationServiceFactoryOptions export function keyGenerationServiceFactory( cache: { keyGenerationService?: KeyGenerationService } & CachedServices, opts: KeyGenerationServiceInitOptions -): KeyGenerationService { +): Promise { return factory( cache, "keyGenerationService", opts, - () => new KeyGenerationService(cryptoFunctionServiceFactory(cache, opts)) + async () => new KeyGenerationService(await cryptoFunctionServiceFactory(cache, opts)) ); } diff --git a/apps/browser/src/background/service_factories/log-service.factory.ts b/apps/browser/src/background/service_factories/log-service.factory.ts index 407aadd12f6..f8c7f9cad22 100644 --- a/apps/browser/src/background/service_factories/log-service.factory.ts +++ b/apps/browser/src/background/service_factories/log-service.factory.ts @@ -16,7 +16,7 @@ export type LogServiceInitOptions = LogServiceFactoryOptions; export function logServiceFactory( cache: { logService?: LogService } & CachedServices, opts: LogServiceInitOptions -): LogService { +): Promise { return factory( cache, "logService", diff --git a/apps/browser/src/background/service_factories/messaging-service.factory.ts b/apps/browser/src/background/service_factories/messaging-service.factory.ts new file mode 100644 index 00000000000..633f1b2d578 --- /dev/null +++ b/apps/browser/src/background/service_factories/messaging-service.factory.ts @@ -0,0 +1,16 @@ +import { MessagingService as AbstractMessagingService } from "@bitwarden/common/abstractions/messaging.service"; + +import BrowserMessagingService from "../../services/browserMessaging.service"; + +import { CachedServices, factory, FactoryOptions } from "./factory-options"; + +type MessagingServiceFactoryOptions = FactoryOptions; + +export type MessagingServiceInitOptions = MessagingServiceFactoryOptions; + +export function messagingServiceFactory( + cache: { messagingService?: AbstractMessagingService } & CachedServices, + opts: MessagingServiceInitOptions +): Promise { + return factory(cache, "messagingService", opts, () => new BrowserMessagingService()); +} diff --git a/apps/browser/src/background/service_factories/organization-service.factory.ts b/apps/browser/src/background/service_factories/organization-service.factory.ts new file mode 100644 index 00000000000..87692e64391 --- /dev/null +++ b/apps/browser/src/background/service_factories/organization-service.factory.ts @@ -0,0 +1,22 @@ +import { OrganizationService as AbstractOrganizationService } from "@bitwarden/common/abstractions/organization.service"; +import { OrganizationService } from "@bitwarden/common/services/organization.service"; + +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; + +type OrganizationServiceFactoryOptions = FactoryOptions; + +export type OrganizationServiceInitOptions = OrganizationServiceFactoryOptions & + StateServiceInitOptions; + +export function organizationServiceFactory( + cache: { organizationService?: AbstractOrganizationService } & CachedServices, + opts: OrganizationServiceInitOptions +): Promise { + return factory( + cache, + "organizationService", + opts, + async () => new OrganizationService(await stateServiceFactory(cache, opts)) + ); +} diff --git a/apps/browser/src/background/service_factories/platform-utils-service.factory.ts b/apps/browser/src/background/service_factories/platform-utils-service.factory.ts new file mode 100644 index 00000000000..6d85f126361 --- /dev/null +++ b/apps/browser/src/background/service_factories/platform-utils-service.factory.ts @@ -0,0 +1,34 @@ +import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; + +import BrowserPlatformUtilsService from "../../services/browserPlatformUtils.service"; + +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { MessagingServiceInitOptions, messagingServiceFactory } from "./messaging-service.factory"; + +type PlatformUtilsServiceFactoryOptions = FactoryOptions & { + platformUtilsServiceOptions: { + clipboardWriteCallback: (clipboardValue: string, clearMs: number) => Promise; + biometricCallback: () => Promise; + win: Window & typeof globalThis; + }; +}; + +export type PlatformUtilsServiceInitOptions = PlatformUtilsServiceFactoryOptions & + MessagingServiceInitOptions; + +export function platformUtilsServiceFactory( + cache: { platformUtilsService?: PlatformUtilsService } & CachedServices, + opts: PlatformUtilsServiceInitOptions +): Promise { + return factory( + cache, + "platformUtilsService", + opts, + async () => + new BrowserPlatformUtilsService( + await messagingServiceFactory(cache, opts), + opts.platformUtilsServiceOptions.clipboardWriteCallback, + opts.platformUtilsServiceOptions.biometricCallback + ) + ); +} diff --git a/apps/browser/src/background/service_factories/policy-service.factory.ts b/apps/browser/src/background/service_factories/policy-service.factory.ts new file mode 100644 index 00000000000..d4940bef259 --- /dev/null +++ b/apps/browser/src/background/service_factories/policy-service.factory.ts @@ -0,0 +1,34 @@ +import { PolicyService as AbstractPolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; +import { PolicyService } from "@bitwarden/common/services/policy/policy.service"; + +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { + organizationServiceFactory, + OrganizationServiceInitOptions, +} from "./organization-service.factory"; +import { + stateServiceFactory as stateServiceFactory, + StateServiceInitOptions, +} from "./state-service.factory"; + +type PolicyServiceFactoryOptions = FactoryOptions; + +export type PolicyServiceInitOptions = PolicyServiceFactoryOptions & + StateServiceInitOptions & + OrganizationServiceInitOptions; + +export function policyServiceFactory( + cache: { policyService?: AbstractPolicyService } & CachedServices, + opts: PolicyServiceInitOptions +): Promise { + return factory( + cache, + "policyService", + opts, + async () => + new PolicyService( + await stateServiceFactory(cache, opts), + await organizationServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/search-service.factory.ts b/apps/browser/src/background/service_factories/search-service.factory.ts new file mode 100644 index 00000000000..29318c45250 --- /dev/null +++ b/apps/browser/src/background/service_factories/search-service.factory.ts @@ -0,0 +1,31 @@ +import { SearchService as AbstractSearchService } from "@bitwarden/common/abstractions/search.service"; +import { SearchService } from "@bitwarden/common/services/search.service"; + +import { cipherServiceFactory, CipherServiceInitOptions } from "./cipher-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { i18nServiceFactory, I18nServiceInitOptions } from "./i18n-service.factory"; +import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"; + +type SearchServiceFactoryOptions = FactoryOptions; + +export type SearchServiceInitOptions = SearchServiceFactoryOptions & + CipherServiceInitOptions & + LogServiceInitOptions & + I18nServiceInitOptions; + +export function searchServiceFactory( + cache: { searchService?: AbstractSearchService } & CachedServices, + opts: SearchServiceInitOptions +): Promise { + return factory( + cache, + "searchService", + opts, + async () => + new SearchService( + await cipherServiceFactory(cache, opts), + await logServiceFactory(cache, opts), + await i18nServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/background/service_factories/settings-service.factory.ts b/apps/browser/src/background/service_factories/settings-service.factory.ts new file mode 100644 index 00000000000..745a6d08d60 --- /dev/null +++ b/apps/browser/src/background/service_factories/settings-service.factory.ts @@ -0,0 +1,21 @@ +import { SettingsService as AbstractSettingsService } from "@bitwarden/common/abstractions/settings.service"; +import { SettingsService } from "@bitwarden/common/services/settings.service"; + +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; + +type SettingsServiceFactoryOptions = FactoryOptions; + +export type SettingsServiceInitOptions = SettingsServiceFactoryOptions & StateServiceInitOptions; + +export function settingsServiceFactory( + cache: { settingsService?: AbstractSettingsService } & CachedServices, + opts: SettingsServiceInitOptions +): Promise { + return factory( + cache, + "settingsService", + opts, + async () => new SettingsService(await stateServiceFactory(cache, opts)) + ); +} diff --git a/apps/browser/src/background/service_factories/state-migration-service.factory.ts b/apps/browser/src/background/service_factories/state-migration-service.factory.ts index cffa7ee765f..ae21298b72a 100644 --- a/apps/browser/src/background/service_factories/state-migration-service.factory.ts +++ b/apps/browser/src/background/service_factories/state-migration-service.factory.ts @@ -25,15 +25,15 @@ export type StateMigrationServiceInitOptions = StateMigrationServiceFactoryOptio export function stateMigrationServiceFactory( cache: { stateMigrationService?: StateMigrationService } & CachedServices, opts: StateMigrationServiceInitOptions -): StateMigrationService { +): Promise { return factory( cache, "stateMigrationService", opts, - () => + async () => new StateMigrationService( - diskStorageServiceFactory(cache, opts), - secureStorageServiceFactory(cache, opts), + await diskStorageServiceFactory(cache, opts), + await secureStorageServiceFactory(cache, opts), opts.stateMigrationServiceOptions.stateFactory ) ); diff --git a/apps/browser/src/background/service_factories/state-service.factory.ts b/apps/browser/src/background/service_factories/state-service.factory.ts index f936afbbc10..202148cd746 100644 --- a/apps/browser/src/background/service_factories/state-service.factory.ts +++ b/apps/browser/src/background/service_factories/state-service.factory.ts @@ -33,23 +33,25 @@ export type StateServiceInitOptions = StateServiceFactoryOptions & LogServiceInitOptions & StateMigrationServiceInitOptions; -export function stateServiceFactory( +export async function stateServiceFactory( cache: { stateService?: StateService } & CachedServices, opts: StateServiceInitOptions -): StateService { - return factory( +): Promise { + const service = await factory( cache, "stateService", opts, - () => - new StateService( - diskStorageServiceFactory(cache, opts), - secureStorageServiceFactory(cache, opts), - memoryStorageServiceFactory(cache, opts), - logServiceFactory(cache, opts), - stateMigrationServiceFactory(cache, opts), + async () => + await new StateService( + await diskStorageServiceFactory(cache, opts), + await secureStorageServiceFactory(cache, opts), + await memoryStorageServiceFactory(cache, opts), + await logServiceFactory(cache, opts), + await stateMigrationServiceFactory(cache, opts), opts.stateServiceOptions.stateFactory, opts.stateServiceOptions.useAccountCache ) ); + service.init(); + return service; } diff --git a/apps/browser/src/background/service_factories/storage-service.factory.ts b/apps/browser/src/background/service_factories/storage-service.factory.ts index 8ef7e1e93a8..09ee4c7371a 100644 --- a/apps/browser/src/background/service_factories/storage-service.factory.ts +++ b/apps/browser/src/background/service_factories/storage-service.factory.ts @@ -22,26 +22,26 @@ export type MemoryStorageServiceInitOptions = StorageServiceFactoryOptions & export function diskStorageServiceFactory( cache: { diskStorageService?: AbstractStorageService } & CachedServices, opts: DiskStorageServiceInitOptions -): AbstractStorageService { +): Promise { return factory(cache, "diskStorageService", opts, () => new BrowserLocalStorageService()); } export function secureStorageServiceFactory( cache: { secureStorageService?: AbstractStorageService } & CachedServices, opts: SecureStorageServiceInitOptions -): AbstractStorageService { +): Promise { return factory(cache, "secureStorageService", opts, () => new BrowserLocalStorageService()); } export function memoryStorageServiceFactory( cache: { memoryStorageService?: AbstractStorageService } & CachedServices, opts: MemoryStorageServiceInitOptions -): AbstractStorageService { - return factory(cache, "memoryStorageService", opts, () => { +): Promise { + return factory(cache, "memoryStorageService", opts, async () => { if (chrome.runtime.getManifest().manifest_version == 3) { return new LocalBackedSessionStorageService( - encryptServiceFactory(cache, opts), - keyGenerationServiceFactory(cache, opts) + await encryptServiceFactory(cache, opts), + await keyGenerationServiceFactory(cache, opts) ); } return new MemoryStorageService(); diff --git a/apps/browser/src/background/service_factories/token-service.factory.ts b/apps/browser/src/background/service_factories/token-service.factory.ts new file mode 100644 index 00000000000..2b642985e24 --- /dev/null +++ b/apps/browser/src/background/service_factories/token-service.factory.ts @@ -0,0 +1,21 @@ +import { TokenService as AbstractTokenService } from "@bitwarden/common/abstractions/token.service"; +import { TokenService } from "@bitwarden/common/services/token.service"; + +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory"; + +type TokenServiceFactoryOptions = FactoryOptions; + +export type TokenServiceInitOptions = TokenServiceFactoryOptions & StateServiceInitOptions; + +export function tokenServiceFactory( + cache: { tokenService?: AbstractTokenService } & CachedServices, + opts: TokenServiceInitOptions +): Promise { + return factory( + cache, + "tokenService", + opts, + async () => new TokenService(await stateServiceFactory(cache, opts)) + ); +} diff --git a/apps/browser/src/background/service_factories/two-factor-service.factory.ts b/apps/browser/src/background/service_factories/two-factor-service.factory.ts new file mode 100644 index 00000000000..07bed5400b4 --- /dev/null +++ b/apps/browser/src/background/service_factories/two-factor-service.factory.ts @@ -0,0 +1,33 @@ +import { TwoFactorService as AbstractTwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service"; +import { TwoFactorService } from "@bitwarden/common/services/twoFactor.service"; + +import { FactoryOptions, CachedServices, factory } from "./factory-options"; +import { I18nServiceInitOptions, i18nServiceFactory } from "./i18n-service.factory"; +import { + platformUtilsServiceFactory, + PlatformUtilsServiceInitOptions, +} from "./platform-utils-service.factory"; + +type TwoFactorServiceFactoryOptions = FactoryOptions; + +export type TwoFactorServiceInitOptions = TwoFactorServiceFactoryOptions & + I18nServiceInitOptions & + PlatformUtilsServiceInitOptions; + +export async function twoFactorServiceFactory( + cache: { twoFactorService?: AbstractTwoFactorService } & CachedServices, + opts: TwoFactorServiceInitOptions +): Promise { + const service = await factory( + cache, + "twoFactorService", + opts, + async () => + new TwoFactorService( + await i18nServiceFactory(cache, opts), + await platformUtilsServiceFactory(cache, opts) + ) + ); + await service.init(); + return service; +} diff --git a/apps/browser/src/background/service_factories/vault-timeout-service.factory.ts b/apps/browser/src/background/service_factories/vault-timeout-service.factory.ts new file mode 100644 index 00000000000..3029b94f008 --- /dev/null +++ b/apps/browser/src/background/service_factories/vault-timeout-service.factory.ts @@ -0,0 +1,78 @@ +import { VaultTimeoutService as AbstractVaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; + +import VaultTimeoutService from "../../services/vaultTimeout/vaultTimeout.service"; + +import { authServiceFactory, AuthServiceInitOptions } from "./auth-service.factory"; +import { cipherServiceFactory, CipherServiceInitOptions } from "./cipher-service.factory"; +import { + collectionServiceFactory, + CollectionServiceInitOptions, +} from "./collection-service.factory"; +import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { folderServiceFactory, FolderServiceInitOptions } from "./folder-service.factory"; +import { + keyConnectorServiceFactory, + KeyConnectorServiceInitOptions, +} from "./key-connector-service.factory"; +import { messagingServiceFactory, MessagingServiceInitOptions } from "./messaging-service.factory"; +import { + platformUtilsServiceFactory, + PlatformUtilsServiceInitOptions, +} from "./platform-utils-service.factory"; +import { searchServiceFactory, SearchServiceInitOptions } from "./search-service.factory"; +import { + stateServiceFactory as stateServiceFactory, + StateServiceInitOptions, +} from "./state-service.factory"; +import { + vaultTimeoutSettingsServiceFactory, + VaultTimeoutSettingsServiceInitOptions, +} from "./vault-timeout-settings-service.factory"; + +type VaultTimeoutServiceFactoryOptions = FactoryOptions & { + vaultTimeoutServiceOptions: { + lockedCallback: (userId?: string) => Promise; + loggedOutCallback: (expired: boolean, userId?: string) => Promise; + }; +}; + +export type VaultTimeoutServiceInitOptions = VaultTimeoutServiceFactoryOptions & + CipherServiceInitOptions & + FolderServiceInitOptions & + CollectionServiceInitOptions & + CryptoServiceInitOptions & + PlatformUtilsServiceInitOptions & + MessagingServiceInitOptions & + SearchServiceInitOptions & + KeyConnectorServiceInitOptions & + StateServiceInitOptions & + AuthServiceInitOptions & + VaultTimeoutSettingsServiceInitOptions; + +export function vaultTimeoutServiceFactory( + cache: { vaultTimeoutService?: AbstractVaultTimeoutService } & CachedServices, + opts: VaultTimeoutServiceInitOptions +): Promise { + return factory( + cache, + "vaultTimeoutService", + opts, + async () => + new VaultTimeoutService( + await cipherServiceFactory(cache, opts), + await folderServiceFactory(cache, opts), + await collectionServiceFactory(cache, opts), + await cryptoServiceFactory(cache, opts), + await platformUtilsServiceFactory(cache, opts), + await messagingServiceFactory(cache, opts), + await searchServiceFactory(cache, opts), + await keyConnectorServiceFactory(cache, opts), + await stateServiceFactory(cache, opts), + await authServiceFactory(cache, opts), + await vaultTimeoutSettingsServiceFactory(cache, opts), + opts.vaultTimeoutServiceOptions.lockedCallback, + opts.vaultTimeoutServiceOptions.loggedOutCallback + ) + ); +} diff --git a/apps/browser/src/background/service_factories/vault-timeout-settings-service.factory.ts b/apps/browser/src/background/service_factories/vault-timeout-settings-service.factory.ts new file mode 100644 index 00000000000..0d8ed149b88 --- /dev/null +++ b/apps/browser/src/background/service_factories/vault-timeout-settings-service.factory.ts @@ -0,0 +1,37 @@ +import { VaultTimeoutSettingsService as AbstractVaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vaultTimeout/vaultTimeoutSettings.service"; + +import { cryptoServiceFactory, CryptoServiceInitOptions } from "./crypto-service.factory"; +import { CachedServices, factory, FactoryOptions } from "./factory-options"; +import { policyServiceFactory, PolicyServiceInitOptions } from "./policy-service.factory"; +import { + stateServiceFactory as stateServiceFactory, + StateServiceInitOptions, +} from "./state-service.factory"; +import { tokenServiceFactory, TokenServiceInitOptions } from "./token-service.factory"; + +type VaultTimeoutSettingsServiceFactoryOptions = FactoryOptions; + +export type VaultTimeoutSettingsServiceInitOptions = VaultTimeoutSettingsServiceFactoryOptions & + CryptoServiceInitOptions & + TokenServiceInitOptions & + PolicyServiceInitOptions & + StateServiceInitOptions; + +export function vaultTimeoutSettingsServiceFactory( + cache: { vaultTimeoutSettingsService?: AbstractVaultTimeoutSettingsService } & CachedServices, + opts: VaultTimeoutSettingsServiceInitOptions +): Promise { + return factory( + cache, + "vaultTimeoutSettingsService", + opts, + async () => + new VaultTimeoutSettingsService( + await cryptoServiceFactory(cache, opts), + await tokenServiceFactory(cache, opts), + await policyServiceFactory(cache, opts), + await stateServiceFactory(cache, opts) + ) + ); +} diff --git a/apps/browser/src/listeners/onInstallListener.ts b/apps/browser/src/listeners/onInstallListener.ts index 8d871b7788b..63414d633ff 100644 --- a/apps/browser/src/listeners/onInstallListener.ts +++ b/apps/browser/src/listeners/onInstallListener.ts @@ -5,7 +5,7 @@ import { environmentServiceFactory } from "../background/service_factories/envir import { BrowserApi } from "../browser/browserApi"; import { Account } from "../models/account"; -export function onInstallListener(details: chrome.runtime.InstalledDetails) { +export async function onInstallListener(details: chrome.runtime.InstalledDetails) { const cache = {}; const opts = { encryptServiceOptions: { @@ -24,7 +24,7 @@ export function onInstallListener(details: chrome.runtime.InstalledDetails) { stateFactory: new StateFactory(GlobalState, Account), }, }; - const environmentService = environmentServiceFactory(cache, opts); + const environmentService = await environmentServiceFactory(cache, opts); setTimeout(async () => { if (details.reason != null && details.reason === "install") { diff --git a/apps/browser/src/popup/accounts/lock.component.ts b/apps/browser/src/popup/accounts/lock.component.ts index 15e15de297a..c288a54a65b 100644 --- a/apps/browser/src/popup/accounts/lock.component.ts +++ b/apps/browser/src/popup/accounts/lock.component.ts @@ -12,8 +12,9 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors"; @@ -37,6 +38,7 @@ export class LockComponent extends BaseLockComponent { messagingService: MessagingService, cryptoService: CryptoService, vaultTimeoutService: VaultTimeoutService, + vaultTimeoutSettingsService: VaultTimeoutSettingsService, environmentService: EnvironmentService, stateService: StateService, apiService: ApiService, @@ -53,6 +55,7 @@ export class LockComponent extends BaseLockComponent { messagingService, cryptoService, vaultTimeoutService, + vaultTimeoutSettingsService, environmentService, stateService, apiService, diff --git a/apps/browser/src/popup/accounts/login.component.ts b/apps/browser/src/popup/accounts/login.component.ts index edd197ca183..83c654d6737 100644 --- a/apps/browser/src/popup/accounts/login.component.ts +++ b/apps/browser/src/popup/accounts/login.component.ts @@ -10,7 +10,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-login", diff --git a/apps/browser/src/popup/accounts/set-password.component.ts b/apps/browser/src/popup/accounts/set-password.component.ts index c4837f6a8e3..a9d16d7305e 100644 --- a/apps/browser/src/popup/accounts/set-password.component.ts +++ b/apps/browser/src/popup/accounts/set-password.component.ts @@ -12,7 +12,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-set-password", diff --git a/apps/browser/src/popup/accounts/sso.component.ts b/apps/browser/src/popup/accounts/sso.component.ts index d737bc724b4..7483cc51a27 100644 --- a/apps/browser/src/popup/accounts/sso.component.ts +++ b/apps/browser/src/popup/accounts/sso.component.ts @@ -11,8 +11,8 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { BrowserApi } from "../../browser/browserApi"; diff --git a/apps/browser/src/popup/accounts/two-factor.component.ts b/apps/browser/src/popup/accounts/two-factor.component.ts index 0a0bbcaec85..55294ef2e1e 100644 --- a/apps/browser/src/popup/accounts/two-factor.component.ts +++ b/apps/browser/src/popup/accounts/two-factor.component.ts @@ -13,7 +13,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service"; import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType"; diff --git a/apps/browser/src/popup/accounts/update-temp-password.component.ts b/apps/browser/src/popup/accounts/update-temp-password.component.ts index 0910bd4d190..9468209f36e 100644 --- a/apps/browser/src/popup/accounts/update-temp-password.component.ts +++ b/apps/browser/src/popup/accounts/update-temp-password.component.ts @@ -10,7 +10,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-update-temp-password", diff --git a/apps/browser/src/popup/send/send-groupings.component.ts b/apps/browser/src/popup/send/send-groupings.component.ts index 5faa1a3c848..0805742666d 100644 --- a/apps/browser/src/popup/send/send-groupings.component.ts +++ b/apps/browser/src/popup/send/send-groupings.component.ts @@ -10,7 +10,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { SendService } from "@bitwarden/common/abstractions/send.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { SendType } from "@bitwarden/common/enums/sendType"; import { SendView } from "@bitwarden/common/models/view/sendView"; diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 265c765cbb6..c070db6087a 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -41,13 +41,14 @@ import { SendService } from "@bitwarden/common/abstractions/send.service"; import { SettingsService } from "@bitwarden/common/abstractions/settings.service"; import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TokenService } from "@bitwarden/common/abstractions/token.service"; import { TotpService } from "@bitwarden/common/abstractions/totp.service"; import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service"; import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { UsernameGenerationService } from "@bitwarden/common/abstractions/usernameGeneration.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { AuthService } from "@bitwarden/common/services/auth.service"; import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service"; import { SearchService } from "@bitwarden/common/services/search.service"; @@ -237,6 +238,11 @@ function getBgService(service: keyof MainBackground) { useFactory: getBgService("userVerificationService"), deps: [], }, + { + provide: VaultTimeoutSettingsService, + useFactory: getBgService("vaultTimeoutSettingsService"), + deps: [], + }, { provide: VaultTimeoutService, useFactory: getBgService("vaultTimeoutService"), diff --git a/apps/browser/src/popup/settings/settings.component.ts b/apps/browser/src/popup/settings/settings.component.ts index e91e8e47d4c..029812ba49b 100644 --- a/apps/browser/src/popup/settings/settings.component.ts +++ b/apps/browser/src/popup/settings/settings.component.ts @@ -11,7 +11,8 @@ import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { DeviceType } from "@bitwarden/common/enums/deviceType"; import { BrowserApi } from "../../browser/browserApi"; @@ -57,6 +58,7 @@ export class SettingsComponent implements OnInit { private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, private vaultTimeoutService: VaultTimeoutService, + private vaultTimeoutSettingsService: VaultTimeoutSettingsService, public messagingService: MessagingService, private router: Router, private environmentService: EnvironmentService, @@ -95,7 +97,7 @@ export class SettingsComponent implements OnInit { { name: this.i18nService.t("logOut"), value: "logOut" }, ]; - let timeout = await this.vaultTimeoutService.getVaultTimeout(); + let timeout = await this.vaultTimeoutSettingsService.getVaultTimeout(); if (timeout != null) { if (timeout === -2 && !showOnLocked) { timeout = -1; @@ -111,11 +113,11 @@ export class SettingsComponent implements OnInit { const action = await this.stateService.getVaultTimeoutAction(); this.vaultTimeoutAction = action == null ? "lock" : action; - const pinSet = await this.vaultTimeoutService.isPinLockSet(); + const pinSet = await this.vaultTimeoutSettingsService.isPinLockSet(); this.pin = pinSet[0] || pinSet[1]; this.supportsBiometric = await this.platformUtilsService.supportsBiometric(); - this.biometric = await this.vaultTimeoutService.isBiometricLockSet(); + this.biometric = await this.vaultTimeoutSettingsService.isBiometricLockSet(); this.enableAutoBiometricsPrompt = !(await this.stateService.getDisableAutoBiometricsPrompt()); this.showChangeMasterPass = !(await this.keyConnectorService.getUsesKeyConnector()); } @@ -148,7 +150,7 @@ export class SettingsComponent implements OnInit { this.previousVaultTimeout = this.vaultTimeout.value; - await this.vaultTimeoutService.setVaultTimeoutOptions( + await this.vaultTimeoutSettingsService.setVaultTimeoutOptions( this.vaultTimeout.value, this.vaultTimeoutAction ); @@ -187,7 +189,7 @@ export class SettingsComponent implements OnInit { } this.vaultTimeoutAction = newValue; - await this.vaultTimeoutService.setVaultTimeoutOptions( + await this.vaultTimeoutSettingsService.setVaultTimeoutOptions( this.vaultTimeout.value, this.vaultTimeoutAction ); @@ -205,7 +207,7 @@ export class SettingsComponent implements OnInit { this.pin = await ref.onClosedPromise(); } else { await this.cryptoService.clearPinProtectedKey(); - await this.vaultTimeoutService.clear(); + await this.vaultTimeoutSettingsService.clear(); } } diff --git a/apps/browser/src/popup/settings/sync.component.ts b/apps/browser/src/popup/settings/sync.component.ts index 9647178906f..4b77870aa1d 100644 --- a/apps/browser/src/popup/settings/sync.component.ts +++ b/apps/browser/src/popup/settings/sync.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from "@angular/core"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-sync", diff --git a/apps/browser/src/popup/vault/current-tab.component.ts b/apps/browser/src/popup/vault/current-tab.component.ts index 7d5cf00466d..2f3569841f4 100644 --- a/apps/browser/src/popup/vault/current-tab.component.ts +++ b/apps/browser/src/popup/vault/current-tab.component.ts @@ -9,7 +9,7 @@ import { PasswordRepromptService } from "@bitwarden/common/abstractions/password import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { CipherRepromptType } from "@bitwarden/common/enums/cipherRepromptType"; import { CipherType } from "@bitwarden/common/enums/cipherType"; import { Utils } from "@bitwarden/common/misc/utils"; diff --git a/apps/browser/src/popup/vault/vault-filter.component.ts b/apps/browser/src/popup/vault/vault-filter.component.ts index 603c5a031e7..13b3018b663 100644 --- a/apps/browser/src/popup/vault/vault-filter.component.ts +++ b/apps/browser/src/popup/vault/vault-filter.component.ts @@ -9,7 +9,7 @@ import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.s import { CipherService } from "@bitwarden/common/abstractions/cipher.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { CipherType } from "@bitwarden/common/enums/cipherType"; import { TreeNode } from "@bitwarden/common/models/domain/treeNode"; import { CipherView } from "@bitwarden/common/models/view/cipherView"; diff --git a/apps/browser/src/services/vaultTimeout.service.ts b/apps/browser/src/services/vaultTimeout/vaultTimeout.service.ts similarity index 88% rename from apps/browser/src/services/vaultTimeout.service.ts rename to apps/browser/src/services/vaultTimeout/vaultTimeout.service.ts index 8dc67a494bb..d6f6c3bd178 100644 --- a/apps/browser/src/services/vaultTimeout.service.ts +++ b/apps/browser/src/services/vaultTimeout/vaultTimeout.service.ts @@ -1,6 +1,6 @@ -import { VaultTimeoutService as BaseVaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; +import { VaultTimeoutService as BaseVaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service"; -import { SafariApp } from "../browser/safariApp"; +import { SafariApp } from "../../browser/safariApp"; export default class VaultTimeoutService extends BaseVaultTimeoutService { startCheck() { diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 9f9998af894..a168182ddc5 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -40,13 +40,14 @@ import { SendService } from "@bitwarden/common/services/send.service"; import { SettingsService } from "@bitwarden/common/services/settings.service"; import { StateService } from "@bitwarden/common/services/state.service"; import { StateMigrationService } from "@bitwarden/common/services/stateMigration.service"; -import { SyncService } from "@bitwarden/common/services/sync.service"; +import { SyncService } from "@bitwarden/common/services/sync/sync.service"; import { TokenService } from "@bitwarden/common/services/token.service"; import { TotpService } from "@bitwarden/common/services/totp.service"; import { TwoFactorService } from "@bitwarden/common/services/twoFactor.service"; import { UserVerificationApiService } from "@bitwarden/common/services/userVerification/userVerification-api.service"; import { UserVerificationService } from "@bitwarden/common/services/userVerification/userVerification.service"; -import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vaultTimeout/vaultTimeoutSettings.service"; import { CliPlatformUtilsService } from "@bitwarden/node/cli/services/cliPlatformUtils.service"; import { ConsoleLogService } from "@bitwarden/node/cli/services/consoleLog.service"; import { NodeApiService } from "@bitwarden/node/services/nodeApi.service"; @@ -82,6 +83,7 @@ export class Main { folderService: InternalFolderService; collectionService: CollectionService; vaultTimeoutService: VaultTimeoutService; + vaultTimeoutSettingsService: VaultTimeoutSettingsService; syncService: SyncService; passwordGenerationService: PasswordGenerationService; totpService: TotpService; @@ -273,6 +275,13 @@ export class Main { const lockedCallback = async () => await this.cryptoService.clearStoredKey(KeySuffixOptions.Auto); + this.vaultTimeoutSettingsService = new VaultTimeoutSettingsService( + this.cryptoService, + this.tokenService, + this.policyService, + this.stateService + ); + this.vaultTimeoutService = new VaultTimeoutService( this.cipherService, this.folderService, @@ -281,11 +290,10 @@ export class Main { this.platformUtilsService, this.messagingService, this.searchService, - this.tokenService, - this.policyService, this.keyConnectorService, this.stateService, this.authService, + this.vaultTimeoutSettingsService, lockedCallback, null ); diff --git a/apps/cli/src/commands/convertToKeyConnector.command.ts b/apps/cli/src/commands/convertToKeyConnector.command.ts index e1b4b3b2548..6339fa9b9aa 100644 --- a/apps/cli/src/commands/convertToKeyConnector.command.ts +++ b/apps/cli/src/commands/convertToKeyConnector.command.ts @@ -3,7 +3,7 @@ import * as inquirer from "inquirer"; import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { Response } from "@bitwarden/node/cli/models/response"; import { MessageResponse } from "@bitwarden/node/cli/models/response/messageResponse"; diff --git a/apps/cli/src/commands/lock.command.ts b/apps/cli/src/commands/lock.command.ts index 9a7e807d0fd..ee993376fd8 100644 --- a/apps/cli/src/commands/lock.command.ts +++ b/apps/cli/src/commands/lock.command.ts @@ -1,4 +1,4 @@ -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { Response } from "@bitwarden/node/cli/models/response"; import { MessageResponse } from "@bitwarden/node/cli/models/response/messageResponse"; diff --git a/apps/cli/src/commands/login.command.ts b/apps/cli/src/commands/login.command.ts index 57a502ecd4a..d88a4d6d2f0 100644 --- a/apps/cli/src/commands/login.command.ts +++ b/apps/cli/src/commands/login.command.ts @@ -11,7 +11,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service"; import { Utils } from "@bitwarden/common/misc/utils"; import { LoginCommand as BaseLoginCommand } from "@bitwarden/node/cli/commands/login.command"; diff --git a/apps/cli/src/commands/status.command.ts b/apps/cli/src/commands/status.command.ts index 6ea053888e4..1b8d5fa3f56 100644 --- a/apps/cli/src/commands/status.command.ts +++ b/apps/cli/src/commands/status.command.ts @@ -1,7 +1,7 @@ import { AuthService } from "@bitwarden/common/abstractions/auth.service"; import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { Response } from "@bitwarden/node/cli/models/response"; diff --git a/apps/cli/src/commands/sync.command.ts b/apps/cli/src/commands/sync.command.ts index 377a3f23b93..40fc42fb410 100644 --- a/apps/cli/src/commands/sync.command.ts +++ b/apps/cli/src/commands/sync.command.ts @@ -1,4 +1,4 @@ -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { Response } from "@bitwarden/node/cli/models/response"; import { MessageResponse } from "@bitwarden/node/cli/models/response/messageResponse"; import { StringResponse } from "@bitwarden/node/cli/models/response/stringResponse"; diff --git a/apps/cli/src/commands/unlock.command.ts b/apps/cli/src/commands/unlock.command.ts index 760149de55a..4318a22cbdc 100644 --- a/apps/cli/src/commands/unlock.command.ts +++ b/apps/cli/src/commands/unlock.command.ts @@ -5,7 +5,7 @@ import { EnvironmentService } from "@bitwarden/common/abstractions/environment.s import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { HashPurpose } from "@bitwarden/common/enums/hashPurpose"; import { Utils } from "@bitwarden/common/misc/utils"; import { SecretVerificationRequest } from "@bitwarden/common/models/request/secretVerificationRequest"; diff --git a/apps/desktop/src/app/accounts/lock.component.ts b/apps/desktop/src/app/accounts/lock.component.ts index 08c73c78b8f..ff136aa982e 100644 --- a/apps/desktop/src/app/accounts/lock.component.ts +++ b/apps/desktop/src/app/accounts/lock.component.ts @@ -13,8 +13,9 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; const BroadcasterSubscriptionId = "LockComponent"; @@ -34,6 +35,7 @@ export class LockComponent extends BaseLockComponent { messagingService: MessagingService, cryptoService: CryptoService, vaultTimeoutService: VaultTimeoutService, + vaultTimeoutSettingsService: VaultTimeoutSettingsService, environmentService: EnvironmentService, stateService: StateService, apiService: ApiService, @@ -51,6 +53,7 @@ export class LockComponent extends BaseLockComponent { messagingService, cryptoService, vaultTimeoutService, + vaultTimeoutSettingsService, environmentService, stateService, apiService, diff --git a/apps/desktop/src/app/accounts/login.component.ts b/apps/desktop/src/app/accounts/login.component.ts index c0bce046c82..959c8a45650 100644 --- a/apps/desktop/src/app/accounts/login.component.ts +++ b/apps/desktop/src/app/accounts/login.component.ts @@ -13,7 +13,7 @@ import { MessagingService } from "@bitwarden/common/abstractions/messaging.servi import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { EnvironmentComponent } from "./environment.component"; diff --git a/apps/desktop/src/app/accounts/set-password.component.ts b/apps/desktop/src/app/accounts/set-password.component.ts index 77470066855..ca82aaed5e6 100644 --- a/apps/desktop/src/app/accounts/set-password.component.ts +++ b/apps/desktop/src/app/accounts/set-password.component.ts @@ -13,7 +13,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; const BroadcasterSubscriptionId = "SetPasswordComponent"; diff --git a/apps/desktop/src/app/accounts/settings.component.ts b/apps/desktop/src/app/accounts/settings.component.ts index 0fd9f99d57e..24c1ba576f6 100644 --- a/apps/desktop/src/app/accounts/settings.component.ts +++ b/apps/desktop/src/app/accounts/settings.component.ts @@ -9,7 +9,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { DeviceType } from "@bitwarden/common/enums/deviceType"; import { StorageLocation } from "@bitwarden/common/enums/storageLocation"; import { ThemeType } from "@bitwarden/common/enums/themeType"; @@ -76,7 +76,7 @@ export class SettingsComponent implements OnInit { constructor( private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, - private vaultTimeoutService: VaultTimeoutService, + private vaultTimeoutSettingsService: VaultTimeoutSettingsService, private stateService: StateService, private messagingService: MessagingService, private cryptoService: CryptoService, @@ -184,7 +184,7 @@ export class SettingsComponent implements OnInit { this.saveVaultTimeoutOptions(); }); - const pinSet = await this.vaultTimeoutService.isPinLockSet(); + const pinSet = await this.vaultTimeoutSettingsService.isPinLockSet(); this.pin = pinSet[0] || pinSet[1]; // Account preferences @@ -195,7 +195,7 @@ export class SettingsComponent implements OnInit { this.clearClipboard = await this.stateService.getClearClipboard(); this.minimizeOnCopyToClipboard = await this.stateService.getMinimizeOnCopyToClipboard(); this.supportsBiometric = await this.platformUtilsService.supportsBiometric(); - this.biometric = await this.vaultTimeoutService.isBiometricLockSet(); + this.biometric = await this.vaultTimeoutSettingsService.isBiometricLockSet(); this.biometricText = await this.stateService.getBiometricText(); this.autoPromptBiometrics = !(await this.stateService.getNoAutoPromptBiometrics()); this.autoPromptBiometricsText = await this.stateService.getNoAutoPromptBiometricsText(); @@ -246,7 +246,7 @@ export class SettingsComponent implements OnInit { this.previousVaultTimeout = this.vaultTimeout.value; - await this.vaultTimeoutService.setVaultTimeoutOptions( + await this.vaultTimeoutSettingsService.setVaultTimeoutOptions( this.vaultTimeout.value, this.vaultTimeoutAction ); @@ -265,7 +265,7 @@ export class SettingsComponent implements OnInit { } if (!this.pin) { await this.cryptoService.clearPinProtectedKey(); - await this.vaultTimeoutService.clear(); + await this.vaultTimeoutSettingsService.clear(); } } diff --git a/apps/desktop/src/app/accounts/sso.component.ts b/apps/desktop/src/app/accounts/sso.component.ts index ff0831de490..1d0aebaa873 100644 --- a/apps/desktop/src/app/accounts/sso.component.ts +++ b/apps/desktop/src/app/accounts/sso.component.ts @@ -11,7 +11,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-sso", diff --git a/apps/desktop/src/app/accounts/two-factor.component.ts b/apps/desktop/src/app/accounts/two-factor.component.ts index b5dd8df0c7a..51ad6e13297 100644 --- a/apps/desktop/src/app/accounts/two-factor.component.ts +++ b/apps/desktop/src/app/accounts/two-factor.component.ts @@ -11,7 +11,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service"; import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType"; diff --git a/apps/desktop/src/app/accounts/update-temp-password.component.ts b/apps/desktop/src/app/accounts/update-temp-password.component.ts index 768bdb4e2e9..109eec23003 100644 --- a/apps/desktop/src/app/accounts/update-temp-password.component.ts +++ b/apps/desktop/src/app/accounts/update-temp-password.component.ts @@ -10,7 +10,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-update-temp-password", diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index 29cefbe02da..0541e5493ca 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -33,9 +33,10 @@ import { InternalPolicyService } from "@bitwarden/common/abstractions/policy/pol import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { SettingsService } from "@bitwarden/common/abstractions/settings.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { SystemService } from "@bitwarden/common/abstractions/system.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus"; import { CipherType } from "@bitwarden/common/enums/cipherType"; @@ -114,6 +115,7 @@ export class AppComponent implements OnInit, OnDestroy { private sanitizer: DomSanitizer, private ngZone: NgZone, private vaultTimeoutService: VaultTimeoutService, + private vaultTimeoutSettingsService: VaultTimeoutSettingsService, private cryptoService: CryptoService, private logService: LogService, private messagingService: MessagingService, @@ -471,7 +473,7 @@ export class AppComponent implements OnInit, OnDestroy { this.folderService.clear(userBeingLoggedOut), this.collectionService.clear(userBeingLoggedOut), this.passwordGenerationService.clear(userBeingLoggedOut), - this.vaultTimeoutService.clear(userBeingLoggedOut), + this.vaultTimeoutSettingsService.clear(userBeingLoggedOut), this.policyService.clear(userBeingLoggedOut), this.keyConnectorService.clear(), ]); diff --git a/apps/desktop/src/app/services/init.service.ts b/apps/desktop/src/app/services/init.service.ts index e99c47823d5..41e6c6a1da9 100644 --- a/apps/desktop/src/app/services/init.service.ts +++ b/apps/desktop/src/app/services/init.service.ts @@ -9,12 +9,12 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstrac import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/abstractions/state.service"; -import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/abstractions/twoFactor.service"; -import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { ContainerService } from "@bitwarden/common/services/container.service"; import { EventService } from "@bitwarden/common/services/event.service"; -import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service"; import { I18nService } from "../../services/i18n.service"; import { NativeMessagingService } from "../../services/nativeMessaging.service"; diff --git a/apps/desktop/src/app/vault/vault.component.ts b/apps/desktop/src/app/vault/vault.component.ts index 3deae9fc725..c3437063021 100644 --- a/apps/desktop/src/app/vault/vault.component.ts +++ b/apps/desktop/src/app/vault/vault.component.ts @@ -20,7 +20,7 @@ import { MessagingService } from "@bitwarden/common/abstractions/messaging.servi import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TotpService } from "@bitwarden/common/abstractions/totp.service"; import { CipherRepromptType } from "@bitwarden/common/enums/cipherRepromptType"; import { CipherType } from "@bitwarden/common/enums/cipherType"; diff --git a/apps/web/src/app/accounts/lock.component.ts b/apps/web/src/app/accounts/lock.component.ts index 08d69d3316b..0aed1fb0eae 100644 --- a/apps/web/src/app/accounts/lock.component.ts +++ b/apps/web/src/app/accounts/lock.component.ts @@ -11,7 +11,8 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { RouterService } from "../core"; @@ -27,6 +28,7 @@ export class LockComponent extends BaseLockComponent { messagingService: MessagingService, cryptoService: CryptoService, vaultTimeoutService: VaultTimeoutService, + vaultTimeoutSettingsService: VaultTimeoutSettingsService, environmentService: EnvironmentService, private routerService: RouterService, stateService: StateService, @@ -42,6 +44,7 @@ export class LockComponent extends BaseLockComponent { messagingService, cryptoService, vaultTimeoutService, + vaultTimeoutSettingsService, environmentService, stateService, apiService, diff --git a/apps/web/src/app/accounts/set-password.component.ts b/apps/web/src/app/accounts/set-password.component.ts index 771a71affa4..7e337314121 100644 --- a/apps/web/src/app/accounts/set-password.component.ts +++ b/apps/web/src/app/accounts/set-password.component.ts @@ -12,7 +12,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-set-password", diff --git a/apps/web/src/app/accounts/trial-initiation/billing.component.ts b/apps/web/src/app/accounts/trial-initiation/billing.component.ts index 3cff0c82d29..7bf672d09a2 100644 --- a/apps/web/src/app/accounts/trial-initiation/billing.component.ts +++ b/apps/web/src/app/accounts/trial-initiation/billing.component.ts @@ -11,7 +11,7 @@ import { OrganizationService } from "@bitwarden/common/abstractions/organization import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { ProductType } from "@bitwarden/common/enums/productType"; import { OrganizationPlansComponent } from "../../settings/organization-plans.component"; diff --git a/apps/web/src/app/accounts/update-temp-password.component.ts b/apps/web/src/app/accounts/update-temp-password.component.ts index 2360d9c5a70..1bdc2b3becc 100644 --- a/apps/web/src/app/accounts/update-temp-password.component.ts +++ b/apps/web/src/app/accounts/update-temp-password.component.ts @@ -10,7 +10,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; @Component({ selector: "app-update-temp-password", diff --git a/apps/web/src/app/app.component.ts b/apps/web/src/app/app.component.ts index ae9107ea0ec..b1700a85513 100644 --- a/apps/web/src/app/app.component.ts +++ b/apps/web/src/app/app.component.ts @@ -23,8 +23,8 @@ import { InternalPolicyService } from "@bitwarden/common/abstractions/policy/pol import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { SettingsService } from "@bitwarden/common/abstractions/settings.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { PolicyListService, RouterService } from "./core"; import { DisableSendPolicy } from "./organizations/policies/disable-send.component"; diff --git a/apps/web/src/app/core/init.service.ts b/apps/web/src/app/core/init.service.ts index 940ee501685..4915b0a088b 100644 --- a/apps/web/src/app/core/init.service.ts +++ b/apps/web/src/app/core/init.service.ts @@ -12,10 +12,10 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstrac import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/abstractions/state.service"; import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/abstractions/twoFactor.service"; -import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; import { ContainerService } from "@bitwarden/common/services/container.service"; import { EventService as EventLoggingService } from "@bitwarden/common/services/event.service"; -import { VaultTimeoutService as VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; +import { VaultTimeoutService as VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service"; import { I18nService } from "./i18n.service"; diff --git a/apps/web/src/app/layouts/navbar.component.ts b/apps/web/src/app/layouts/navbar.component.ts index bbd4644bdb3..3552ce12233 100644 --- a/apps/web/src/app/layouts/navbar.component.ts +++ b/apps/web/src/app/layouts/navbar.component.ts @@ -6,7 +6,7 @@ import { MessagingService } from "@bitwarden/common/abstractions/messaging.servi import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ProviderService } from "@bitwarden/common/abstractions/provider.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TokenService } from "@bitwarden/common/abstractions/token.service"; import { Utils } from "@bitwarden/common/misc/utils"; import { Organization } from "@bitwarden/common/models/domain/organization"; diff --git a/apps/web/src/app/organizations/guards/org-permissions.guard.spec.ts b/apps/web/src/app/organizations/guards/org-permissions.guard.spec.ts index 03d91822a52..59f7c5390a9 100644 --- a/apps/web/src/app/organizations/guards/org-permissions.guard.spec.ts +++ b/apps/web/src/app/organizations/guards/org-permissions.guard.spec.ts @@ -9,7 +9,7 @@ import { mock, MockProxy } from "jest-mock-extended"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType"; import { Organization } from "@bitwarden/common/models/domain/organization"; diff --git a/apps/web/src/app/organizations/guards/org-permissions.guard.ts b/apps/web/src/app/organizations/guards/org-permissions.guard.ts index 31642a44a4b..45c2b8f8bf2 100644 --- a/apps/web/src/app/organizations/guards/org-permissions.guard.ts +++ b/apps/web/src/app/organizations/guards/org-permissions.guard.ts @@ -4,7 +4,7 @@ import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { canAccessOrgAdmin } from "../navigation-permissions"; diff --git a/apps/web/src/app/organizations/manage/people.component.ts b/apps/web/src/app/organizations/manage/people.component.ts index 25649be59eb..ca232c70fc0 100644 --- a/apps/web/src/app/organizations/manage/people.component.ts +++ b/apps/web/src/app/organizations/manage/people.component.ts @@ -17,7 +17,7 @@ import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/poli import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType"; import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType"; import { PolicyType } from "@bitwarden/common/enums/policyType"; diff --git a/apps/web/src/app/organizations/settings/account.component.ts b/apps/web/src/app/organizations/settings/account.component.ts index cf4a5afdf70..f8a909f1eda 100644 --- a/apps/web/src/app/organizations/settings/account.component.ts +++ b/apps/web/src/app/organizations/settings/account.component.ts @@ -9,7 +9,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { OrganizationKeysRequest } from "@bitwarden/common/models/request/organizationKeysRequest"; import { OrganizationUpdateRequest } from "@bitwarden/common/models/request/organizationUpdateRequest"; import { OrganizationResponse } from "@bitwarden/common/models/response/organizationResponse"; diff --git a/apps/web/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts b/apps/web/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts index 8420fd91223..673ffa586d6 100644 --- a/apps/web/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts +++ b/apps/web/src/app/organizations/sponsorships/families-for-enterprise-setup.component.ts @@ -8,7 +8,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { PlanSponsorshipType } from "@bitwarden/common/enums/planSponsorshipType"; import { PlanType } from "@bitwarden/common/enums/planType"; import { ProductType } from "@bitwarden/common/enums/productType"; diff --git a/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts b/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts index c2977180d4b..ae700771a52 100644 --- a/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts +++ b/apps/web/src/app/organizations/users/enroll-master-password-reset.component.ts @@ -8,7 +8,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { Utils } from "@bitwarden/common/misc/utils"; import { Organization } from "@bitwarden/common/models/domain/organization"; diff --git a/apps/web/src/app/organizations/vault/vault.component.ts b/apps/web/src/app/organizations/vault/vault.component.ts index c25e565e78c..f9c378b6393 100644 --- a/apps/web/src/app/organizations/vault/vault.component.ts +++ b/apps/web/src/app/organizations/vault/vault.component.ts @@ -19,7 +19,7 @@ import { MessagingService } from "@bitwarden/common/abstractions/messaging.servi import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { CipherType } from "@bitwarden/common/enums/cipherType"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { CipherView } from "@bitwarden/common/models/view/cipherView"; diff --git a/apps/web/src/app/settings/change-password.component.ts b/apps/web/src/app/settings/change-password.component.ts index abd8daaf4a0..7636c6970b5 100644 --- a/apps/web/src/app/settings/change-password.component.ts +++ b/apps/web/src/app/settings/change-password.component.ts @@ -17,7 +17,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { SendService } from "@bitwarden/common/abstractions/send.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { EmergencyAccessStatusType } from "@bitwarden/common/enums/emergencyAccessStatusType"; import { Utils } from "@bitwarden/common/misc/utils"; import { EncString } from "@bitwarden/common/models/domain/encString"; diff --git a/apps/web/src/app/settings/organization-plans.component.ts b/apps/web/src/app/settings/organization-plans.component.ts index 12fcb4ad40d..7dc6f28e7fb 100644 --- a/apps/web/src/app/settings/organization-plans.component.ts +++ b/apps/web/src/app/settings/organization-plans.component.ts @@ -11,7 +11,7 @@ import { OrganizationService } from "@bitwarden/common/abstractions/organization import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { PaymentMethodType } from "@bitwarden/common/enums/paymentMethodType"; import { PlanType } from "@bitwarden/common/enums/planType"; import { PolicyType } from "@bitwarden/common/enums/policyType"; diff --git a/apps/web/src/app/settings/preferences.component.ts b/apps/web/src/app/settings/preferences.component.ts index 83abd0257ba..c96a1368fe4 100644 --- a/apps/web/src/app/settings/preferences.component.ts +++ b/apps/web/src/app/settings/preferences.component.ts @@ -6,7 +6,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { ThemeType } from "@bitwarden/common/enums/themeType"; import { Utils } from "@bitwarden/common/misc/utils"; @@ -33,7 +33,7 @@ export class PreferencesComponent implements OnInit { constructor( private stateService: StateService, private i18nService: I18nService, - private vaultTimeoutService: VaultTimeoutService, + private vaultTimeoutSettingsService: VaultTimeoutSettingsService, private platformUtilsService: PlatformUtilsService, private messagingService: MessagingService, private themingService: AbstractThemingService @@ -70,7 +70,7 @@ export class PreferencesComponent implements OnInit { } async ngOnInit() { - this.vaultTimeout.setValue(await this.vaultTimeoutService.getVaultTimeout()); + this.vaultTimeout.setValue(await this.vaultTimeoutSettingsService.getVaultTimeout()); this.vaultTimeoutAction = await this.stateService.getVaultTimeoutAction(); this.enableFavicons = !(await this.stateService.getDisableFavicon()); this.enableGravatars = await this.stateService.getEnableGravitars(); @@ -93,7 +93,7 @@ export class PreferencesComponent implements OnInit { return; } - await this.vaultTimeoutService.setVaultTimeoutOptions( + await this.vaultTimeoutSettingsService.setVaultTimeoutOptions( this.vaultTimeout.value, this.vaultTimeoutAction ); diff --git a/apps/web/src/app/settings/premium.component.ts b/apps/web/src/app/settings/premium.component.ts index 80ded51a216..49fbe09fa47 100644 --- a/apps/web/src/app/settings/premium.component.ts +++ b/apps/web/src/app/settings/premium.component.ts @@ -7,7 +7,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TokenService } from "@bitwarden/common/abstractions/token.service"; import { PaymentComponent } from "./payment.component"; diff --git a/apps/web/src/app/settings/sponsored-families.component.ts b/apps/web/src/app/settings/sponsored-families.component.ts index 814b522ee6c..d2233fc6c8a 100644 --- a/apps/web/src/app/settings/sponsored-families.component.ts +++ b/apps/web/src/app/settings/sponsored-families.component.ts @@ -7,7 +7,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { PlanSponsorshipType } from "@bitwarden/common/enums/planSponsorshipType"; import { Organization } from "@bitwarden/common/models/domain/organization"; diff --git a/apps/web/src/app/settings/update-key.component.ts b/apps/web/src/app/settings/update-key.component.ts index b995ce42bf9..bf0afc150d6 100644 --- a/apps/web/src/app/settings/update-key.component.ts +++ b/apps/web/src/app/settings/update-key.component.ts @@ -9,7 +9,7 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { EncString } from "@bitwarden/common/models/domain/encString"; import { CipherWithIdRequest } from "@bitwarden/common/models/request/cipherWithIdRequest"; import { FolderWithIdRequest } from "@bitwarden/common/models/request/folderWithIdRequest"; diff --git a/apps/web/src/app/tools/import-export/export.component.ts b/apps/web/src/app/tools/import-export/export.component.ts index 1b5738885bc..5d704bb5f69 100644 --- a/apps/web/src/app/tools/import-export/export.component.ts +++ b/apps/web/src/app/tools/import-export/export.component.ts @@ -14,7 +14,7 @@ import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.serv import { UserVerificationService } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { EncryptedExportType } from "@bitwarden/common/enums/encryptedExportType"; -import { UserVerificationPromptComponent } from "src/app/components/user-verification-prompt.component"; +import { UserVerificationPromptComponent } from "../../components/user-verification-prompt.component"; @Component({ selector: "app-export", diff --git a/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts b/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts index c23beb96e90..efffd7d54a2 100644 --- a/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts +++ b/apps/web/src/app/vault/vault-filter/organization-filter/organization-options.component.ts @@ -7,7 +7,7 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { PolicyType } from "@bitwarden/common/enums/policyType"; import { Organization } from "@bitwarden/common/models/domain/organization"; import { Policy } from "@bitwarden/common/models/domain/policy"; diff --git a/apps/web/src/app/vault/vault.component.ts b/apps/web/src/app/vault/vault.component.ts index 4430328dd33..c9d6b590390 100644 --- a/apps/web/src/app/vault/vault.component.ts +++ b/apps/web/src/app/vault/vault.component.ts @@ -21,7 +21,7 @@ import { OrganizationService } from "@bitwarden/common/abstractions/organization import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TokenService } from "@bitwarden/common/abstractions/token.service"; import { CipherView } from "@bitwarden/common/models/view/cipherView"; diff --git a/apps/web/src/locales/en/messages.json b/apps/web/src/locales/en/messages.json index dd074b9cd2b..68ff1271c8a 100644 --- a/apps/web/src/locales/en/messages.json +++ b/apps/web/src/locales/en/messages.json @@ -912,10 +912,10 @@ "message": "Confirm File Password" }, "accountBackupOptionDescription": { - "message": "Leverages your Bitwarden account encryption, not master password, to protect the export. This export can only be imported into the current account. Use this to create a backup that cannot be used elsewhere." + "message": "Use your account encryption key to encrypt the export and restrict import to only the current Bitwarden account." }, "passwordProtectedOptionDescription": { - "message": "Create a user-generated password to protect the export. Use this to create an export that can be used in other accounts." + "message": "Set a password to encrypt the export and import it to any Bitwarden account using the password for decryption." }, "fileTypeHeading": { "message": "File Type" diff --git a/bitwarden_license/bit-web/src/app/providers/services/webProvider.service.ts b/bitwarden_license/bit-web/src/app/providers/services/webProvider.service.ts index b6a7c07d28b..c11735367d0 100644 --- a/bitwarden_license/bit-web/src/app/providers/services/webProvider.service.ts +++ b/bitwarden_license/bit-web/src/app/providers/services/webProvider.service.ts @@ -2,7 +2,7 @@ import { Injectable } from "@angular/core"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { ProviderAddOrganizationRequest } from "@bitwarden/common/models/request/provider/providerAddOrganizationRequest"; @Injectable() diff --git a/bitwarden_license/bit-web/src/app/providers/settings/account.component.ts b/bitwarden_license/bit-web/src/app/providers/settings/account.component.ts index 4359cd9fb47..94a99ed5c60 100644 --- a/bitwarden_license/bit-web/src/app/providers/settings/account.component.ts +++ b/bitwarden_license/bit-web/src/app/providers/settings/account.component.ts @@ -5,7 +5,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { ProviderUpdateRequest } from "@bitwarden/common/models/request/provider/providerUpdateRequest"; import { ProviderResponse } from "@bitwarden/common/models/response/provider/providerResponse"; diff --git a/bitwarden_license/bit-web/src/app/providers/setup/setup.component.ts b/bitwarden_license/bit-web/src/app/providers/setup/setup.component.ts index 4919cb7e9ea..531f1e9e21a 100644 --- a/bitwarden_license/bit-web/src/app/providers/setup/setup.component.ts +++ b/bitwarden_license/bit-web/src/app/providers/setup/setup.component.ts @@ -7,7 +7,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { ProviderSetupRequest } from "@bitwarden/common/models/request/provider/providerSetupRequest"; @Component({ diff --git a/libs/angular/src/components/lock.component.ts b/libs/angular/src/components/lock.component.ts index 63ed0e9f1d9..d00127ae965 100644 --- a/libs/angular/src/components/lock.component.ts +++ b/libs/angular/src/components/lock.component.ts @@ -12,7 +12,8 @@ import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { HashPurpose } from "@bitwarden/common/enums/hashPurpose"; import { KeySuffixOptions } from "@bitwarden/common/enums/keySuffixOptions"; import { Utils } from "@bitwarden/common/misc/utils"; @@ -49,6 +50,7 @@ export class LockComponent implements OnInit, OnDestroy { protected messagingService: MessagingService, protected cryptoService: CryptoService, protected vaultTimeoutService: VaultTimeoutService, + protected vaultTimeoutSettingsService: VaultTimeoutSettingsService, protected environmentService: EnvironmentService, protected stateService: StateService, protected apiService: ApiService, @@ -262,13 +264,13 @@ export class LockComponent implements OnInit, OnDestroy { } private async load() { - this.pinSet = await this.vaultTimeoutService.isPinLockSet(); + this.pinSet = await this.vaultTimeoutSettingsService.isPinLockSet(); this.pinLock = (this.pinSet[0] && (await this.stateService.getDecryptedPinProtected()) != null) || this.pinSet[1]; this.supportsBiometric = await this.platformUtilsService.supportsBiometric(); this.biometricLock = - (await this.vaultTimeoutService.isBiometricLockSet()) && + (await this.vaultTimeoutSettingsService.isBiometricLockSet()) && ((await this.cryptoService.hasKeyStored(KeySuffixOptions.Biometric)) || !this.platformUtilsService.supportsSecureStorage()); this.biometricText = await this.stateService.getBiometricText(); diff --git a/libs/angular/src/components/remove-password.component.ts b/libs/angular/src/components/remove-password.component.ts index 7bbf0d2ae9b..20d7cc247ab 100644 --- a/libs/angular/src/components/remove-password.component.ts +++ b/libs/angular/src/components/remove-password.component.ts @@ -7,7 +7,7 @@ import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { Organization } from "@bitwarden/common/models/domain/organization"; @Directive() diff --git a/libs/angular/src/components/set-password.component.ts b/libs/angular/src/components/set-password.component.ts index 36792a3f374..373a1bab99b 100644 --- a/libs/angular/src/components/set-password.component.ts +++ b/libs/angular/src/components/set-password.component.ts @@ -12,7 +12,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { HashPurpose } from "@bitwarden/common/enums/hashPurpose"; import { DEFAULT_KDF_ITERATIONS, DEFAULT_KDF_TYPE } from "@bitwarden/common/enums/kdfType"; import { Utils } from "@bitwarden/common/misc/utils"; diff --git a/libs/angular/src/components/update-temp-password.component.ts b/libs/angular/src/components/update-temp-password.component.ts index 7f36abd9a60..63aecec9968 100644 --- a/libs/angular/src/components/update-temp-password.component.ts +++ b/libs/angular/src/components/update-temp-password.component.ts @@ -9,7 +9,7 @@ import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwo import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { SyncService } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { EncString } from "@bitwarden/common/models/domain/encString"; import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/masterPasswordPolicyOptions"; import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetricCryptoKey"; diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index a1625ab7549..ab51488ffe5 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -46,14 +46,15 @@ import { SettingsService as SettingsServiceAbstraction } from "@bitwarden/common import { StateService as StateServiceAbstraction } from "@bitwarden/common/abstractions/state.service"; import { StateMigrationService as StateMigrationServiceAbstraction } from "@bitwarden/common/abstractions/stateMigration.service"; import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; -import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync.service"; +import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/abstractions/sync/sync.service.abstraction"; import { TokenService as TokenServiceAbstraction } from "@bitwarden/common/abstractions/token.service"; import { TotpService as TotpServiceAbstraction } from "@bitwarden/common/abstractions/totp.service"; import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/abstractions/twoFactor.service"; import { UserVerificationApiServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification-api.service.abstraction"; import { UserVerificationService as UserVerificationServiceAbstraction } from "@bitwarden/common/abstractions/userVerification/userVerification.service.abstraction"; import { UsernameGenerationService as UsernameGenerationServiceAbstraction } from "@bitwarden/common/abstractions/usernameGeneration.service"; -import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout.service"; +import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service"; import { StateFactory } from "@bitwarden/common/factories/stateFactory"; import { Account } from "@bitwarden/common/models/domain/account"; import { GlobalState } from "@bitwarden/common/models/domain/globalState"; @@ -88,14 +89,15 @@ import { SendService } from "@bitwarden/common/services/send.service"; import { SettingsService } from "@bitwarden/common/services/settings.service"; import { StateService } from "@bitwarden/common/services/state.service"; import { StateMigrationService } from "@bitwarden/common/services/stateMigration.service"; -import { SyncService } from "@bitwarden/common/services/sync.service"; +import { SyncService } from "@bitwarden/common/services/sync/sync.service"; import { TokenService } from "@bitwarden/common/services/token.service"; import { TotpService } from "@bitwarden/common/services/totp.service"; import { TwoFactorService } from "@bitwarden/common/services/twoFactor.service"; import { UserVerificationApiService } from "@bitwarden/common/services/userVerification/userVerification-api.service"; import { UserVerificationService } from "@bitwarden/common/services/userVerification/userVerification.service"; import { UsernameGenerationService } from "@bitwarden/common/services/usernameGeneration.service"; -import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; +import { VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vaultTimeout/vaultTimeoutSettings.service"; import { WebCryptoFunctionService } from "@bitwarden/common/services/webCryptoFunction.service"; import { AuthGuard } from "../guards/auth.guard"; @@ -344,6 +346,16 @@ export const LOG_MAC_FAILURES = new InjectionToken("LOG_MAC_FAILURES"); useClass: SettingsService, deps: [StateServiceAbstraction], }, + { + provide: VaultTimeoutSettingsServiceAbstraction, + useClass: VaultTimeoutSettingsService, + deps: [ + CryptoServiceAbstraction, + TokenServiceAbstraction, + PolicyServiceAbstraction, + StateServiceAbstraction, + ], + }, { provide: VaultTimeoutServiceAbstraction, useClass: VaultTimeoutService, @@ -355,11 +367,10 @@ export const LOG_MAC_FAILURES = new InjectionToken("LOG_MAC_FAILURES"); PlatformUtilsServiceAbstraction, MessagingServiceAbstraction, SearchServiceAbstraction, - TokenServiceAbstraction, - PolicyServiceAbstraction, KeyConnectorServiceAbstraction, StateServiceAbstraction, AuthServiceAbstraction, + VaultTimeoutSettingsServiceAbstraction, LOCKED_CALLBACK, LOGOUT_CALLBACK, ], diff --git a/libs/common/spec/services/settings.service.spec.ts b/libs/common/spec/services/settings.service.spec.ts new file mode 100644 index 00000000000..f3733a14258 --- /dev/null +++ b/libs/common/spec/services/settings.service.spec.ts @@ -0,0 +1,64 @@ +import { Arg, Substitute, SubstituteOf } from "@fluffy-spoon/substitute"; +import { BehaviorSubject, firstValueFrom } from "rxjs"; + +import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; +import { ContainerService } from "@bitwarden/common/services/container.service"; +import { SettingsService } from "@bitwarden/common/services/settings.service"; +import { StateService } from "@bitwarden/common/services/state.service"; + +describe("SettingsService", () => { + let settingsService: SettingsService; + + let cryptoService: SubstituteOf; + let stateService: SubstituteOf; + let activeAccount: BehaviorSubject; + let activeAccountUnlocked: BehaviorSubject; + + beforeEach(() => { + cryptoService = Substitute.for(); + stateService = Substitute.for(); + activeAccount = new BehaviorSubject("123"); + activeAccountUnlocked = new BehaviorSubject(true); + + stateService.getSettings().resolves({ equivalentDomains: [["test"], ["domains"]] }); + stateService.activeAccount$.returns(activeAccount); + stateService.activeAccountUnlocked$.returns(activeAccountUnlocked); + (window as any).bitwardenContainerService = new ContainerService(cryptoService); + + settingsService = new SettingsService(stateService); + }); + + afterEach(() => { + activeAccount.complete(); + activeAccountUnlocked.complete(); + }); + + describe("getEquivalentDomains", () => { + it("returns value", async () => { + const result = await firstValueFrom(settingsService.settings$); + + expect(result).toEqual({ + equivalentDomains: [["test"], ["domains"]], + }); + }); + }); + + it("setEquivalentDomains", async () => { + await settingsService.setEquivalentDomains([["test2"], ["domains2"]]); + + stateService.received(1).setSettings(Arg.any()); + + expect((await firstValueFrom(settingsService.settings$)).equivalentDomains).toEqual([ + ["test2"], + ["domains2"], + ]); + }); + + it("clear", async () => { + await settingsService.clear(); + + stateService.received(1).setSettings(Arg.any(), Arg.any()); + + expect(await firstValueFrom(settingsService.settings$)).toEqual({}); + }); +}); diff --git a/libs/common/src/abstractions/settings.service.ts b/libs/common/src/abstractions/settings.service.ts index e7886585b48..1f6047dfa10 100644 --- a/libs/common/src/abstractions/settings.service.ts +++ b/libs/common/src/abstractions/settings.service.ts @@ -1,6 +1,10 @@ +import { Observable } from "rxjs"; + +import { AccountSettingsSettings } from "../models/domain/account"; + export abstract class SettingsService { - clearCache: () => Promise; - getEquivalentDomains: () => Promise; + settings$: Observable; + setEquivalentDomains: (equivalentDomains: string[][]) => Promise; clear: (userId?: string) => Promise; } diff --git a/libs/common/src/abstractions/state.service.ts b/libs/common/src/abstractions/state.service.ts index b99d8aef86e..737a51c10b9 100644 --- a/libs/common/src/abstractions/state.service.ts +++ b/libs/common/src/abstractions/state.service.ts @@ -12,7 +12,7 @@ import { OrganizationData } from "../models/data/organizationData"; import { PolicyData } from "../models/data/policyData"; import { ProviderData } from "../models/data/providerData"; import { SendData } from "../models/data/sendData"; -import { Account } from "../models/domain/account"; +import { Account, AccountSettingsSettings } from "../models/domain/account"; import { EncString } from "../models/domain/encString"; import { EnvironmentUrls } from "../models/domain/environmentUrls"; import { GeneratedPasswordHistory } from "../models/domain/generatedPasswordHistory"; @@ -286,8 +286,14 @@ export abstract class StateService { setRememberedEmail: (value: string, options?: StorageOptions) => Promise; getSecurityStamp: (options?: StorageOptions) => Promise; setSecurityStamp: (value: string, options?: StorageOptions) => Promise; - getSettings: (options?: StorageOptions) => Promise; - setSettings: (value: string, options?: StorageOptions) => Promise; + /** + * @deprecated Do not call this directly, use SettingsService + */ + getSettings: (options?: StorageOptions) => Promise; + /** + * @deprecated Do not call this directly, use SettingsService + */ + setSettings: (value: AccountSettingsSettings, options?: StorageOptions) => Promise; getSsoCodeVerifier: (options?: StorageOptions) => Promise; setSsoCodeVerifier: (value: string, options?: StorageOptions) => Promise; getSsoOrgIdentifier: (options?: StorageOptions) => Promise; diff --git a/libs/common/src/abstractions/sync.service.ts b/libs/common/src/abstractions/sync/sync.service.abstraction.ts similarity index 82% rename from libs/common/src/abstractions/sync.service.ts rename to libs/common/src/abstractions/sync/sync.service.abstraction.ts index 936d027fd41..51583fd3c41 100644 --- a/libs/common/src/abstractions/sync.service.ts +++ b/libs/common/src/abstractions/sync/sync.service.abstraction.ts @@ -1,12 +1,17 @@ +import { Observable } from "rxjs"; + import { SyncCipherNotification, SyncFolderNotification, SyncSendNotification, -} from "../models/response/notificationResponse"; +} from "../../models/response/notificationResponse"; +import { SyncEventArgs } from "../../types/syncEventArgs"; export abstract class SyncService { syncInProgress: boolean; + sync$: Observable; + getLastSync: () => Promise; setLastSync: (date: Date, userId?: string) => Promise; fullSync: (forceSync: boolean, allowThrowOnError?: boolean) => Promise; diff --git a/libs/common/src/abstractions/vaultTimeout.service.ts b/libs/common/src/abstractions/vaultTimeout.service.ts deleted file mode 100644 index 4fb474fd034..00000000000 --- a/libs/common/src/abstractions/vaultTimeout.service.ts +++ /dev/null @@ -1,10 +0,0 @@ -export abstract class VaultTimeoutService { - checkVaultTimeout: () => Promise; - lock: (userId?: string) => Promise; - logOut: (userId?: string) => Promise; - setVaultTimeoutOptions: (vaultTimeout: number, vaultTimeoutAction: string) => Promise; - getVaultTimeout: () => Promise; - isPinLockSet: () => Promise<[boolean, boolean]>; - isBiometricLockSet: () => Promise; - clear: (userId?: string) => Promise; -} diff --git a/libs/common/src/abstractions/vaultTimeout/vaultTimeout.service.ts b/libs/common/src/abstractions/vaultTimeout/vaultTimeout.service.ts new file mode 100644 index 00000000000..6baadfc0337 --- /dev/null +++ b/libs/common/src/abstractions/vaultTimeout/vaultTimeout.service.ts @@ -0,0 +1,5 @@ +export abstract class VaultTimeoutService { + checkVaultTimeout: () => Promise; + lock: (userId?: string) => Promise; + logOut: (userId?: string) => Promise; +} diff --git a/libs/common/src/abstractions/vaultTimeout/vaultTimeoutSettings.service.ts b/libs/common/src/abstractions/vaultTimeout/vaultTimeoutSettings.service.ts new file mode 100644 index 00000000000..7e819df6b97 --- /dev/null +++ b/libs/common/src/abstractions/vaultTimeout/vaultTimeoutSettings.service.ts @@ -0,0 +1,7 @@ +export abstract class VaultTimeoutSettingsService { + setVaultTimeoutOptions: (vaultTimeout: number, vaultTimeoutAction: string) => Promise; + getVaultTimeout: (userId?: string) => Promise; + isPinLockSet: () => Promise<[boolean, boolean]>; + isBiometricLockSet: () => Promise; + clear: (userId?: string) => Promise; +} diff --git a/libs/common/src/models/domain/account.ts b/libs/common/src/models/domain/account.ts index 88b6de248cb..dfeacce1207 100644 --- a/libs/common/src/models/domain/account.ts +++ b/libs/common/src/models/domain/account.ts @@ -137,11 +137,15 @@ export class AccountSettings { generatorOptions?: any; pinProtected?: EncryptionPair = new EncryptionPair(); protectedPin?: string; - settings?: any; // TODO: Merge whatever is going on here into the AccountSettings model properly + settings?: AccountSettingsSettings; // TODO: Merge whatever is going on here into the AccountSettings model properly vaultTimeout?: number; vaultTimeoutAction?: string = "lock"; } +export type AccountSettingsSettings = { + equivalentDomains?: { [id: string]: any }; +}; + export class AccountTokens { accessToken?: string; decodedToken?: any; diff --git a/libs/common/src/services/cipher.service.ts b/libs/common/src/services/cipher.service.ts index ebc18b21845..40440ea8bf7 100644 --- a/libs/common/src/services/cipher.service.ts +++ b/libs/common/src/services/cipher.service.ts @@ -1,3 +1,5 @@ +import { firstValueFrom } from "rxjs"; + import { ApiService } from "../abstractions/api.service"; import { CipherService as CipherServiceAbstraction } from "../abstractions/cipher.service"; import { CryptoService } from "../abstractions/crypto.service"; @@ -13,6 +15,7 @@ import { UriMatchType } from "../enums/uriMatchType"; import { sequentialize } from "../misc/sequentialize"; import { Utils } from "../misc/utils"; import { CipherData } from "../models/data/cipherData"; +import { AccountSettingsSettings } from "../models/domain/account"; import { Attachment } from "../models/domain/attachment"; import { Card } from "../models/domain/card"; import { Cipher } from "../models/domain/cipher"; @@ -387,20 +390,22 @@ export class CipherService implements CipherServiceAbstraction { const eqDomainsPromise = domain == null ? Promise.resolve([]) - : this.settingsService.getEquivalentDomains().then((eqDomains: any[][]) => { - let matches: any[] = []; - eqDomains.forEach((eqDomain) => { - if (eqDomain.length && eqDomain.indexOf(domain) >= 0) { - matches = matches.concat(eqDomain); + : firstValueFrom(this.settingsService.settings$).then( + (settings: AccountSettingsSettings) => { + let matches: any[] = []; + settings.equivalentDomains.forEach((eqDomain: any) => { + if (eqDomain.length && eqDomain.indexOf(domain) >= 0) { + matches = matches.concat(eqDomain); + } + }); + + if (!matches.length) { + matches.push(domain); } - }); - if (!matches.length) { - matches.push(domain); + return matches; } - - return matches; - }); + ); const result = await Promise.all([eqDomainsPromise, this.getAllDecrypted()]); const matchingDomains = result[0]; diff --git a/libs/common/src/services/notifications.service.ts b/libs/common/src/services/notifications.service.ts index 39e2df541fe..01975ec592a 100644 --- a/libs/common/src/services/notifications.service.ts +++ b/libs/common/src/services/notifications.service.ts @@ -8,7 +8,7 @@ import { EnvironmentService } from "../abstractions/environment.service"; import { LogService } from "../abstractions/log.service"; import { NotificationsService as NotificationsServiceAbstraction } from "../abstractions/notifications.service"; import { StateService } from "../abstractions/state.service"; -import { SyncService } from "../abstractions/sync.service"; +import { SyncService } from "../abstractions/sync/sync.service.abstraction"; import { AuthenticationStatus } from "../enums/authenticationStatus"; import { NotificationType } from "../enums/notificationType"; import { diff --git a/libs/common/src/services/settings.service.ts b/libs/common/src/services/settings.service.ts index 7f5131b0f34..923bd8970dd 100644 --- a/libs/common/src/services/settings.service.ts +++ b/libs/common/src/services/settings.service.ts @@ -1,56 +1,50 @@ +import { BehaviorSubject, concatMap } from "rxjs"; + import { SettingsService as SettingsServiceAbstraction } from "../abstractions/settings.service"; import { StateService } from "../abstractions/state.service"; - -const Keys = { - settingsPrefix: "settings_", - equivalentDomains: "equivalentDomains", -}; +import { Utils } from "../misc/utils"; +import { AccountSettingsSettings } from "../models/domain/account"; export class SettingsService implements SettingsServiceAbstraction { - constructor(private stateService: StateService) {} + private _settings: BehaviorSubject = new BehaviorSubject({}); - async clearCache(): Promise { - await this.stateService.setSettings(null); - } + settings$ = this._settings.asObservable(); - getEquivalentDomains(): Promise { - return this.getSettingsKey(Keys.equivalentDomains); + constructor(private stateService: StateService) { + this.stateService.activeAccountUnlocked$ + .pipe( + concatMap(async (unlocked) => { + if (Utils.global.bitwardenContainerService == null) { + return; + } + + if (!unlocked) { + this._settings.next({}); + return; + } + + const data = await this.stateService.getSettings(); + + this._settings.next(data); + }) + ) + .subscribe(); } async setEquivalentDomains(equivalentDomains: string[][]): Promise { - await this.setSettingsKey(Keys.equivalentDomains, equivalentDomains); + const settings = this._settings.getValue() ?? {}; + + settings.equivalentDomains = equivalentDomains; + + this._settings.next(settings); + await this.stateService.setSettings(settings); } async clear(userId?: string): Promise { + if (userId == null || userId == (await this.stateService.getUserId())) { + this._settings.next({}); + } + await this.stateService.setSettings(null, { userId: userId }); } - - // Helpers - - private async getSettings(): Promise { - const settings = await this.stateService.getSettings(); - if (settings == null) { - // eslint-disable-next-line - const userId = await this.stateService.getUserId(); - } - return settings; - } - - private async getSettingsKey(key: string): Promise { - const settings = await this.getSettings(); - if (settings != null && settings[key]) { - return settings[key]; - } - return null; - } - - private async setSettingsKey(key: string, value: any): Promise { - let settings = await this.getSettings(); - if (!settings) { - settings = {}; - } - - settings[key] = value; - await this.stateService.setSettings(settings); - } } diff --git a/libs/common/src/services/state.service.ts b/libs/common/src/services/state.service.ts index 3e007911cfb..f2c5a5618dd 100644 --- a/libs/common/src/services/state.service.ts +++ b/libs/common/src/services/state.service.ts @@ -20,7 +20,12 @@ import { OrganizationData } from "../models/data/organizationData"; import { PolicyData } from "../models/data/policyData"; import { ProviderData } from "../models/data/providerData"; import { SendData } from "../models/data/sendData"; -import { Account, AccountData, AccountSettings } from "../models/domain/account"; +import { + Account, + AccountData, + AccountSettings, + AccountSettingsSettings, +} from "../models/domain/account"; import { EncString } from "../models/domain/encString"; import { EnvironmentUrls } from "../models/domain/environmentUrls"; import { GeneratedPasswordHistory } from "../models/domain/generatedPasswordHistory"; @@ -2075,13 +2080,13 @@ export class StateService< ); } - async getSettings(options?: StorageOptions): Promise { + async getSettings(options?: StorageOptions): Promise { return ( await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskMemoryOptions())) )?.settings?.settings; } - async setSettings(value: string, options?: StorageOptions): Promise { + async setSettings(value: AccountSettingsSettings, options?: StorageOptions): Promise { const account = await this.getAccount( this.reconcileOptions(options, await this.defaultOnDiskMemoryOptions()) ); diff --git a/libs/common/src/services/stateMigration.service.ts b/libs/common/src/services/stateMigration.service.ts index 762f2b89770..359b4acec46 100644 --- a/libs/common/src/services/stateMigration.service.ts +++ b/libs/common/src/services/stateMigration.service.ts @@ -12,7 +12,7 @@ import { OrganizationData } from "../models/data/organizationData"; import { PolicyData } from "../models/data/policyData"; import { ProviderData } from "../models/data/providerData"; import { SendData } from "../models/data/sendData"; -import { Account, AccountSettings } from "../models/domain/account"; +import { Account, AccountSettings, AccountSettingsSettings } from "../models/domain/account"; import { EnvironmentUrls } from "../models/domain/environmentUrls"; import { GeneratedPasswordHistory } from "../models/domain/generatedPasswordHistory"; import { GlobalState } from "../models/domain/globalState"; @@ -319,7 +319,10 @@ export class StateMigrationService< encrypted: await this.get(v1Keys.pinProtected), }, protectedPin: await this.get(v1Keys.protectedPin), - settings: userId == null ? null : await this.get(v1KeyPrefixes.settings + userId), + settings: + userId == null + ? null + : await this.get(v1KeyPrefixes.settings + userId), vaultTimeout: (await this.get(v1Keys.vaultTimeout)) ?? defaultAccount.settings.vaultTimeout, vaultTimeoutAction: diff --git a/libs/common/src/services/sync.service.ts b/libs/common/src/services/sync/sync.service.ts similarity index 82% rename from libs/common/src/services/sync.service.ts rename to libs/common/src/services/sync/sync.service.ts index 4776bc97f15..fc460f39206 100644 --- a/libs/common/src/services/sync.service.ts +++ b/libs/common/src/services/sync/sync.service.ts @@ -1,43 +1,50 @@ -import { ApiService } from "../abstractions/api.service"; -import { CipherService } from "../abstractions/cipher.service"; -import { CollectionService } from "../abstractions/collection.service"; -import { CryptoService } from "../abstractions/crypto.service"; -import { FolderApiServiceAbstraction } from "../abstractions/folder/folder-api.service.abstraction"; -import { InternalFolderService } from "../abstractions/folder/folder.service.abstraction"; -import { KeyConnectorService } from "../abstractions/keyConnector.service"; -import { LogService } from "../abstractions/log.service"; -import { MessagingService } from "../abstractions/messaging.service"; -import { OrganizationService } from "../abstractions/organization.service"; -import { InternalPolicyService } from "../abstractions/policy/policy.service.abstraction"; -import { ProviderService } from "../abstractions/provider.service"; -import { SendService } from "../abstractions/send.service"; -import { SettingsService } from "../abstractions/settings.service"; -import { StateService } from "../abstractions/state.service"; -import { SyncService as SyncServiceAbstraction } from "../abstractions/sync.service"; -import { sequentialize } from "../misc/sequentialize"; -import { CipherData } from "../models/data/cipherData"; -import { CollectionData } from "../models/data/collectionData"; -import { FolderData } from "../models/data/folderData"; -import { OrganizationData } from "../models/data/organizationData"; -import { PolicyData } from "../models/data/policyData"; -import { ProviderData } from "../models/data/providerData"; -import { SendData } from "../models/data/sendData"; -import { CipherResponse } from "../models/response/cipherResponse"; -import { CollectionDetailsResponse } from "../models/response/collectionResponse"; -import { DomainsResponse } from "../models/response/domainsResponse"; -import { FolderResponse } from "../models/response/folderResponse"; +import { Subject } from "rxjs"; + +import { ApiService } from "../../abstractions/api.service"; +import { CipherService } from "../../abstractions/cipher.service"; +import { CollectionService } from "../../abstractions/collection.service"; +import { CryptoService } from "../../abstractions/crypto.service"; +import { FolderApiServiceAbstraction } from "../../abstractions/folder/folder-api.service.abstraction"; +import { InternalFolderService } from "../../abstractions/folder/folder.service.abstraction"; +import { KeyConnectorService } from "../../abstractions/keyConnector.service"; +import { LogService } from "../../abstractions/log.service"; +import { MessagingService } from "../../abstractions/messaging.service"; +import { OrganizationService } from "../../abstractions/organization.service"; +import { InternalPolicyService } from "../../abstractions/policy/policy.service.abstraction"; +import { ProviderService } from "../../abstractions/provider.service"; +import { SendService } from "../../abstractions/send.service"; +import { SettingsService } from "../../abstractions/settings.service"; +import { StateService } from "../../abstractions/state.service"; +import { SyncService as SyncServiceAbstraction } from "../../abstractions/sync/sync.service.abstraction"; +import { sequentialize } from "../../misc/sequentialize"; +import { CipherData } from "../../models/data/cipherData"; +import { CollectionData } from "../../models/data/collectionData"; +import { FolderData } from "../../models/data/folderData"; +import { OrganizationData } from "../../models/data/organizationData"; +import { PolicyData } from "../../models/data/policyData"; +import { ProviderData } from "../../models/data/providerData"; +import { SendData } from "../../models/data/sendData"; +import { CipherResponse } from "../../models/response/cipherResponse"; +import { CollectionDetailsResponse } from "../../models/response/collectionResponse"; +import { DomainsResponse } from "../../models/response/domainsResponse"; +import { FolderResponse } from "../../models/response/folderResponse"; import { SyncCipherNotification, SyncFolderNotification, SyncSendNotification, -} from "../models/response/notificationResponse"; -import { PolicyResponse } from "../models/response/policyResponse"; -import { ProfileResponse } from "../models/response/profileResponse"; -import { SendResponse } from "../models/response/sendResponse"; +} from "../../models/response/notificationResponse"; +import { PolicyResponse } from "../../models/response/policyResponse"; +import { ProfileResponse } from "../../models/response/profileResponse"; +import { SendResponse } from "../../models/response/sendResponse"; +import { SyncEventArgs } from "../../types/syncEventArgs"; export class SyncService implements SyncServiceAbstraction { syncInProgress = false; + private _sync = new Subject(); + + sync$ = this._sync.asObservable(); + constructor( private apiService: ApiService, private settingsService: SettingsService, @@ -265,11 +272,13 @@ export class SyncService implements SyncServiceAbstraction { private syncStarted() { this.syncInProgress = true; this.messagingService.send("syncStarted"); + this._sync.next({ status: "Started" }); } private syncCompleted(successfully: boolean): boolean { this.syncInProgress = false; this.messagingService.send("syncCompleted", { successfully: successfully }); + this._sync.next({ status: successfully ? "SuccessfullyCompleted" : "UnsuccessfullyCompleted" }); return successfully; } diff --git a/libs/common/src/services/vaultTimeout.service.ts b/libs/common/src/services/vaultTimeout.service.ts deleted file mode 100644 index 55e347484dc..00000000000 --- a/libs/common/src/services/vaultTimeout.service.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { AuthService } from "../abstractions/auth.service"; -import { CipherService } from "../abstractions/cipher.service"; -import { CollectionService } from "../abstractions/collection.service"; -import { CryptoService } from "../abstractions/crypto.service"; -import { FolderService } from "../abstractions/folder/folder.service.abstraction"; -import { KeyConnectorService } from "../abstractions/keyConnector.service"; -import { MessagingService } from "../abstractions/messaging.service"; -import { PlatformUtilsService } from "../abstractions/platformUtils.service"; -import { PolicyService } from "../abstractions/policy/policy.service.abstraction"; -import { SearchService } from "../abstractions/search.service"; -import { StateService } from "../abstractions/state.service"; -import { TokenService } from "../abstractions/token.service"; -import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "../abstractions/vaultTimeout.service"; -import { AuthenticationStatus } from "../enums/authenticationStatus"; -import { PolicyType } from "../enums/policyType"; - -export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { - private inited = false; - - constructor( - private cipherService: CipherService, - private folderService: FolderService, - private collectionService: CollectionService, - private cryptoService: CryptoService, - protected platformUtilsService: PlatformUtilsService, - private messagingService: MessagingService, - private searchService: SearchService, - private tokenService: TokenService, - private policyService: PolicyService, - private keyConnectorService: KeyConnectorService, - private stateService: StateService, - private authService: AuthService, - private lockedCallback: (userId?: string) => Promise = null, - private loggedOutCallback: (expired: boolean, userId?: string) => Promise = null - ) {} - - init(checkOnInterval: boolean) { - if (this.inited) { - return; - } - - this.inited = true; - if (checkOnInterval) { - this.startCheck(); - } - } - - startCheck() { - this.checkVaultTimeout(); - setInterval(() => this.checkVaultTimeout(), 10 * 1000); // check every 10 seconds - } - - async checkVaultTimeout(): Promise { - if (await this.platformUtilsService.isViewOpen()) { - return; - } - - for (const userId in this.stateService.accounts.getValue()) { - if (userId != null && (await this.shouldLock(userId))) { - await this.executeTimeoutAction(userId); - } - } - } - - async lock(userId?: string): Promise { - const authed = await this.stateService.getIsAuthenticated({ userId: userId }); - if (!authed) { - return; - } - - if (await this.keyConnectorService.getUsesKeyConnector()) { - const pinSet = await this.isPinLockSet(); - const pinLock = - (pinSet[0] && (await this.stateService.getDecryptedPinProtected()) != null) || pinSet[1]; - - if (!pinLock && !(await this.isBiometricLockSet())) { - await this.logOut(userId); - } - } - - if (userId == null || userId === (await this.stateService.getUserId())) { - this.searchService.clearIndex(); - await this.folderService.clearCache(); - } - - await this.stateService.setEverBeenUnlocked(true, { userId: userId }); - await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId }); - - await this.cryptoService.clearKey(false, userId); - await this.cryptoService.clearOrgKeys(true, userId); - await this.cryptoService.clearKeyPair(true, userId); - await this.cryptoService.clearEncKey(true, userId); - - await this.cipherService.clearCache(userId); - await this.collectionService.clearCache(userId); - - this.messagingService.send("locked", { userId: userId }); - - if (this.lockedCallback != null) { - await this.lockedCallback(userId); - } - } - - async logOut(userId?: string): Promise { - if (this.loggedOutCallback != null) { - await this.loggedOutCallback(false, userId); - } - } - - async setVaultTimeoutOptions(timeout: number, action: string): Promise { - await this.stateService.setVaultTimeout(timeout); - - // We swap these tokens from being on disk for lock actions, and in memory for logout actions - // Get them here to set them to their new location after changing the timeout action and clearing if needed - const token = await this.tokenService.getToken(); - const refreshToken = await this.tokenService.getRefreshToken(); - const clientId = await this.tokenService.getClientId(); - const clientSecret = await this.tokenService.getClientSecret(); - - const currentAction = await this.stateService.getVaultTimeoutAction(); - if ((timeout != null || timeout === 0) && action === "logOut" && action !== currentAction) { - // if we have a vault timeout and the action is log out, reset tokens - await this.tokenService.clearToken(); - } - - await this.stateService.setVaultTimeoutAction(action); - - await this.tokenService.setToken(token); - await this.tokenService.setRefreshToken(refreshToken); - await this.tokenService.setClientId(clientId); - await this.tokenService.setClientSecret(clientSecret); - - await this.cryptoService.toggleKey(); - } - - async isPinLockSet(): Promise<[boolean, boolean]> { - const protectedPin = await this.stateService.getProtectedPin(); - const pinProtectedKey = await this.stateService.getEncryptedPinProtected(); - return [protectedPin != null, pinProtectedKey != null]; - } - - async isBiometricLockSet(): Promise { - return await this.stateService.getBiometricUnlock(); - } - - async getVaultTimeout(userId?: string): Promise { - const vaultTimeout = await this.stateService.getVaultTimeout({ userId: userId }); - - if ( - await this.policyService.policyAppliesToUser(PolicyType.MaximumVaultTimeout, null, userId) - ) { - const policy = await this.policyService.getAll(PolicyType.MaximumVaultTimeout, userId); - // Remove negative values, and ensure it's smaller than maximum allowed value according to policy - let timeout = Math.min(vaultTimeout, policy[0].data.minutes); - - if (vaultTimeout == null || timeout < 0) { - timeout = policy[0].data.minutes; - } - - // We really shouldn't need to set the value here, but multiple services relies on this value being correct. - if (vaultTimeout !== timeout) { - await this.stateService.setVaultTimeout(timeout, { userId: userId }); - } - - return timeout; - } - - return vaultTimeout; - } - - async clear(userId?: string): Promise { - await this.stateService.setEverBeenUnlocked(false, { userId: userId }); - await this.stateService.setDecryptedPinProtected(null, { userId: userId }); - await this.stateService.setProtectedPin(null, { userId: userId }); - } - - private async shouldLock(userId: string): Promise { - const authStatus = await this.authService.getAuthStatus(userId); - if ( - authStatus === AuthenticationStatus.Locked || - authStatus === AuthenticationStatus.LoggedOut - ) { - return false; - } - - const vaultTimeout = await this.getVaultTimeout(userId); - if (vaultTimeout == null || vaultTimeout < 0) { - return false; - } - - const lastActive = await this.stateService.getLastActive({ userId: userId }); - if (lastActive == null) { - return false; - } - - const vaultTimeoutSeconds = vaultTimeout * 60; - const diffSeconds = (new Date().getTime() - lastActive) / 1000; - return diffSeconds >= vaultTimeoutSeconds; - } - - private async executeTimeoutAction(userId: string): Promise { - const timeoutAction = await this.stateService.getVaultTimeoutAction({ userId: userId }); - timeoutAction === "logOut" ? await this.logOut(userId) : await this.lock(userId); - } -} diff --git a/libs/common/src/services/vaultTimeout/vaultTimeout.service.ts b/libs/common/src/services/vaultTimeout/vaultTimeout.service.ts new file mode 100644 index 00000000000..f4a9e0330ca --- /dev/null +++ b/libs/common/src/services/vaultTimeout/vaultTimeout.service.ts @@ -0,0 +1,135 @@ +import { AuthService } from "../../abstractions/auth.service"; +import { CipherService } from "../../abstractions/cipher.service"; +import { CollectionService } from "../../abstractions/collection.service"; +import { CryptoService } from "../../abstractions/crypto.service"; +import { FolderService } from "../../abstractions/folder/folder.service.abstraction"; +import { KeyConnectorService } from "../../abstractions/keyConnector.service"; +import { MessagingService } from "../../abstractions/messaging.service"; +import { PlatformUtilsService } from "../../abstractions/platformUtils.service"; +import { SearchService } from "../../abstractions/search.service"; +import { StateService } from "../../abstractions/state.service"; +import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "../../abstractions/vaultTimeout/vaultTimeout.service"; +import { VaultTimeoutSettingsService } from "../../abstractions/vaultTimeout/vaultTimeoutSettings.service"; +import { AuthenticationStatus } from "../../enums/authenticationStatus"; + +export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { + private inited = false; + + constructor( + private cipherService: CipherService, + private folderService: FolderService, + private collectionService: CollectionService, + private cryptoService: CryptoService, + protected platformUtilsService: PlatformUtilsService, + private messagingService: MessagingService, + private searchService: SearchService, + private keyConnectorService: KeyConnectorService, + private stateService: StateService, + private authService: AuthService, + private vaultTimeoutSettingsService: VaultTimeoutSettingsService, + private lockedCallback: (userId?: string) => Promise = null, + private loggedOutCallback: (expired: boolean, userId?: string) => Promise = null + ) {} + + init(checkOnInterval: boolean) { + if (this.inited) { + return; + } + + this.inited = true; + if (checkOnInterval) { + this.startCheck(); + } + } + + startCheck() { + this.checkVaultTimeout(); + setInterval(() => this.checkVaultTimeout(), 10 * 1000); // check every 10 seconds + } + + async checkVaultTimeout(): Promise { + if (await this.platformUtilsService.isViewOpen()) { + return; + } + + for (const userId in this.stateService.accounts.getValue()) { + if (userId != null && (await this.shouldLock(userId))) { + await this.executeTimeoutAction(userId); + } + } + } + + async lock(userId?: string): Promise { + const authed = await this.stateService.getIsAuthenticated({ userId: userId }); + if (!authed) { + return; + } + + if (await this.keyConnectorService.getUsesKeyConnector()) { + const pinSet = await this.vaultTimeoutSettingsService.isPinLockSet(); + const pinLock = + (pinSet[0] && (await this.stateService.getDecryptedPinProtected()) != null) || pinSet[1]; + + if (!pinLock && !(await this.vaultTimeoutSettingsService.isBiometricLockSet())) { + await this.logOut(userId); + } + } + + if (userId == null || userId === (await this.stateService.getUserId())) { + this.searchService.clearIndex(); + await this.folderService.clearCache(); + } + + await this.stateService.setEverBeenUnlocked(true, { userId: userId }); + await this.stateService.setCryptoMasterKeyAuto(null, { userId: userId }); + + await this.cryptoService.clearKey(false, userId); + await this.cryptoService.clearOrgKeys(true, userId); + await this.cryptoService.clearKeyPair(true, userId); + await this.cryptoService.clearEncKey(true, userId); + + await this.cipherService.clearCache(userId); + await this.collectionService.clearCache(userId); + + this.messagingService.send("locked", { userId: userId }); + + if (this.lockedCallback != null) { + await this.lockedCallback(userId); + } + } + + async logOut(userId?: string): Promise { + if (this.loggedOutCallback != null) { + await this.loggedOutCallback(false, userId); + } + } + + private async shouldLock(userId: string): Promise { + const authStatus = await this.authService.getAuthStatus(userId); + if ( + authStatus === AuthenticationStatus.Locked || + authStatus === AuthenticationStatus.LoggedOut + ) { + return false; + } + + const vaultTimeout = await this.vaultTimeoutSettingsService.getVaultTimeout(userId); + if (vaultTimeout == null || vaultTimeout < 0) { + return false; + } + + const lastActive = await this.stateService.getLastActive({ userId: userId }); + if (lastActive == null) { + return false; + } + + const vaultTimeoutSeconds = vaultTimeout * 60; + const diffSeconds = (new Date().getTime() - lastActive) / 1000; + return diffSeconds >= vaultTimeoutSeconds; + } + + private async executeTimeoutAction(userId: string): Promise { + const timeoutAction = await this.stateService.getVaultTimeoutAction({ userId: userId }); + timeoutAction === "logOut" ? await this.logOut(userId) : await this.lock(userId); + } +} diff --git a/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts b/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts new file mode 100644 index 00000000000..4d8b9e0d08c --- /dev/null +++ b/libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts @@ -0,0 +1,82 @@ +import { CryptoService } from "../../abstractions/crypto.service"; +import { PolicyService } from "../../abstractions/policy/policy.service.abstraction"; +import { StateService } from "../../abstractions/state.service"; +import { TokenService } from "../../abstractions/token.service"; +import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "../../abstractions/vaultTimeout/vaultTimeoutSettings.service"; +import { PolicyType } from "../../enums/policyType"; + +export class VaultTimeoutSettingsService implements VaultTimeoutSettingsServiceAbstraction { + constructor( + private cryptoService: CryptoService, + private tokenService: TokenService, + private policyService: PolicyService, + private stateService: StateService + ) {} + + async setVaultTimeoutOptions(timeout: number, action: string): Promise { + await this.stateService.setVaultTimeout(timeout); + + // We swap these tokens from being on disk for lock actions, and in memory for logout actions + // Get them here to set them to their new location after changing the timeout action and clearing if needed + const token = await this.tokenService.getToken(); + const refreshToken = await this.tokenService.getRefreshToken(); + const clientId = await this.tokenService.getClientId(); + const clientSecret = await this.tokenService.getClientSecret(); + + const currentAction = await this.stateService.getVaultTimeoutAction(); + if ((timeout != null || timeout === 0) && action === "logOut" && action !== currentAction) { + // if we have a vault timeout and the action is log out, reset tokens + await this.tokenService.clearToken(); + } + + await this.stateService.setVaultTimeoutAction(action); + + await this.tokenService.setToken(token); + await this.tokenService.setRefreshToken(refreshToken); + await this.tokenService.setClientId(clientId); + await this.tokenService.setClientSecret(clientSecret); + + await this.cryptoService.toggleKey(); + } + + async isPinLockSet(): Promise<[boolean, boolean]> { + const protectedPin = await this.stateService.getProtectedPin(); + const pinProtectedKey = await this.stateService.getEncryptedPinProtected(); + return [protectedPin != null, pinProtectedKey != null]; + } + + async isBiometricLockSet(): Promise { + return await this.stateService.getBiometricUnlock(); + } + + async getVaultTimeout(userId?: string): Promise { + const vaultTimeout = await this.stateService.getVaultTimeout({ userId: userId }); + + if ( + await this.policyService.policyAppliesToUser(PolicyType.MaximumVaultTimeout, null, userId) + ) { + const policy = await this.policyService.getAll(PolicyType.MaximumVaultTimeout, userId); + // Remove negative values, and ensure it's smaller than maximum allowed value according to policy + let timeout = Math.min(vaultTimeout, policy[0].data.minutes); + + if (vaultTimeout == null || timeout < 0) { + timeout = policy[0].data.minutes; + } + + // We really shouldn't need to set the value here, but multiple services relies on this value being correct. + if (vaultTimeout !== timeout) { + await this.stateService.setVaultTimeout(timeout, { userId: userId }); + } + + return timeout; + } + + return vaultTimeout; + } + + async clear(userId?: string): Promise { + await this.stateService.setEverBeenUnlocked(false, { userId: userId }); + await this.stateService.setDecryptedPinProtected(null, { userId: userId }); + await this.stateService.setProtectedPin(null, { userId: userId }); + } +} diff --git a/libs/common/src/types/syncEventArgs.ts b/libs/common/src/types/syncEventArgs.ts new file mode 100644 index 00000000000..3361a3358f1 --- /dev/null +++ b/libs/common/src/types/syncEventArgs.ts @@ -0,0 +1,15 @@ +import { filter } from "rxjs"; + +export type SyncStatus = "Started" | "SuccessfullyCompleted" | "UnsuccessfullyCompleted"; + +export type SyncEventArgs = { + status: SyncStatus; +}; + +/** + * Helper function to filter only on successfully completed syncs + * @returns a function that can be used in a `.pipe()` from an observable + */ +export function onlySuccessfullyCompleted() { + return filter((syncEvent) => syncEvent.status === "SuccessfullyCompleted"); +}