From 3edf098aafb01f739f147f66a9c36e68e24b29fb Mon Sep 17 00:00:00 2001 From: Jason Ng Date: Wed, 14 Feb 2024 17:03:03 -0500 Subject: [PATCH] PM-5274 Migrate Collection Service State (#7732) * update collection service to use new state provider framework, remove stateservice from collection service, update collections state provider with migrate file and unit test --- .../browser/src/background/main.background.ts | 2 +- .../collection-service.factory.ts | 8 +- apps/cli/src/bw.ts | 5 +- apps/web/src/app/core/state/state.service.ts | 16 -- .../vault-header/vault-header.component.html | 2 +- .../vault-header/vault-header.component.ts | 2 +- .../vault-header/vault-header.component.html | 2 +- .../src/services/jslib-services.module.ts | 2 +- .../platform/abstractions/state.service.ts | 9 - .../src/platform/models/domain/account.ts | 8 +- .../src/platform/services/state.service.ts | 43 ---- .../src/platform/state/state-definitions.ts | 3 + .../vault-timeout/vault-timeout.service.ts | 2 +- libs/common/src/state-migrations/migrate.ts | 6 +- ...ollections-state-to-state-provider.spec.ts | 196 ++++++++++++++++++ ...ove-collections-state-to-state-provider.ts | 63 ++++++ libs/common/src/types/guid.ts | 1 + .../vault/abstractions/collection.service.ts | 9 +- .../src/vault/models/data/collection.data.ts | 11 +- .../vault/models/domain/collection.spec.ts | 5 +- .../models/response/collection.response.ts | 5 +- .../src/vault/models/view/collection.view.ts | 6 + .../src/vault/services/collection.service.ts | 190 ++++++++++------- 23 files changed, 426 insertions(+), 170 deletions(-) create mode 100644 libs/common/src/state-migrations/migrations/21-move-collections-state-to-state-provider.spec.ts create mode 100644 libs/common/src/state-migrations/migrations/21-move-collections-state-to-state-provider.ts diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 13732ed0f3a..9420e7d4157 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -454,7 +454,7 @@ export default class MainBackground { this.collectionService = new CollectionService( this.cryptoService, this.i18nService, - this.stateService, + this.stateProvider, ); this.syncNotifierService = new SyncNotifierService(); this.organizationService = new BrowserOrganizationService( diff --git a/apps/browser/src/vault/background/service_factories/collection-service.factory.ts b/apps/browser/src/vault/background/service_factories/collection-service.factory.ts index fd576ca12c3..69d5cd6f22f 100644 --- a/apps/browser/src/vault/background/service_factories/collection-service.factory.ts +++ b/apps/browser/src/vault/background/service_factories/collection-service.factory.ts @@ -14,10 +14,8 @@ import { i18nServiceFactory, I18nServiceInitOptions, } from "../../../platform/background/service-factories/i18n-service.factory"; -import { - stateServiceFactory as stateServiceFactory, - StateServiceInitOptions, -} from "../../../platform/background/service-factories/state-service.factory"; +import { stateProviderFactory } from "../../../platform/background/service-factories/state-provider.factory"; +import { StateServiceInitOptions } from "../../../platform/background/service-factories/state-service.factory"; type CollectionServiceFactoryOptions = FactoryOptions; @@ -38,7 +36,7 @@ export function collectionServiceFactory( new CollectionService( await cryptoServiceFactory(cache, opts), await i18nServiceFactory(cache, opts), - await stateServiceFactory(cache, opts), + await stateProviderFactory(cache, opts), ), ); } diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 05ad43128e5..d1c46e9e0b2 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -87,6 +87,7 @@ import { } from "@bitwarden/common/tools/password-strength"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service"; import { SendService } from "@bitwarden/common/tools/send/services/send.service"; +import { UserId } from "@bitwarden/common/types/guid"; import { InternalFolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction"; import { CipherService } from "@bitwarden/common/vault/services/cipher.service"; import { CollectionService } from "@bitwarden/common/vault/services/collection.service"; @@ -358,7 +359,7 @@ export class Main { this.collectionService = new CollectionService( this.cryptoService, this.i18nService, - this.stateService, + this.stateProvider, ); this.providerService = new ProviderService(this.stateService); @@ -616,7 +617,7 @@ export class Main { this.settingsService.clear(userId), this.cipherService.clear(userId), this.folderService.clear(userId), - this.collectionService.clear(userId), + this.collectionService.clear(userId as UserId), this.policyService.clear(userId), this.passwordGenerationService.clear(), ]); diff --git a/apps/web/src/app/core/state/state.service.ts b/apps/web/src/app/core/state/state.service.ts index a40a24b2155..b46c2b590a0 100644 --- a/apps/web/src/app/core/state/state.service.ts +++ b/apps/web/src/app/core/state/state.service.ts @@ -19,7 +19,6 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service"; import { SendData } from "@bitwarden/common/tools/send/models/data/send.data"; import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data"; -import { CollectionData } from "@bitwarden/common/vault/models/data/collection.data"; import { Account } from "./account"; import { GlobalState } from "./global-state"; @@ -69,21 +68,6 @@ export class StateService extends BaseStateService { return await super.setEncryptedCiphers(value, options); } - async getEncryptedCollections( - options?: StorageOptions, - ): Promise<{ [id: string]: CollectionData }> { - options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); - return await super.getEncryptedCollections(options); - } - - async setEncryptedCollections( - value: { [id: string]: CollectionData }, - options?: StorageOptions, - ): Promise { - options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); - return await super.setEncryptedCollections(value, options); - } - async getEncryptedSends(options?: StorageOptions): Promise<{ [id: string]: SendData }> { options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); return await super.getEncryptedSends(options); diff --git a/apps/web/src/app/vault/individual-vault/vault-header/vault-header.component.html b/apps/web/src/app/vault/individual-vault/vault-header/vault-header.component.html index 851e252e39a..ca8c71cf5df 100644 --- a/apps/web/src/app/vault/individual-vault/vault-header/vault-header.component.html +++ b/apps/web/src/app/vault/individual-vault/vault-header/vault-header.component.html @@ -28,7 +28,7 @@ aria-hidden="true" > {{ title }} - +