From dfdde4daba7c674d6655b331d8710fcfdb28f70e Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Thu, 5 Oct 2023 10:36:27 -0400 Subject: [PATCH] Move state stuff to a single location --- .../src/services/jslib-services.module.ts | 2 +- .../abstractions/global-state.provider.ts | 2 +- .../abstractions/user-state.provider.ts | 2 +- .../src/platform/interfaces/user-state.ts | 3 +- libs/common/src/platform/misc/key-builders.ts | 2 +- .../services/default-global-state.provider.ts | 89 ------------------- .../state/default-global-state.provider.ts | 49 ++++++++++ .../platform/state/default-global-state.ts | 44 +++++++++ .../default-user-state.provider.spec.ts | 4 +- .../state/default-user-state.provider.ts | 42 +++++++++ .../default-user-state.ts} | 87 +++--------------- .../derived-state-definition.ts | 3 +- .../src/platform/state/derived-user-state.ts | 40 +++++++++ libs/common/src/platform/state/index.ts | 13 +++ .../{types => state}/key-definition.ts | 0 .../src/platform/state/key-definitions.ts | 11 +++ .../{types => state}/state-definition.ts | 0 .../state-definitions.spec.ts | 0 .../{types => state}/state-definitions.ts | 0 .../migrations/9-move-folder-to-owned.ts | 4 +- .../vault/services/folder/folder.service.ts | 4 +- .../common/src/vault/types/key-definitions.ts | 10 --- 22 files changed, 222 insertions(+), 189 deletions(-) delete mode 100644 libs/common/src/platform/services/default-global-state.provider.ts create mode 100644 libs/common/src/platform/state/default-global-state.provider.ts create mode 100644 libs/common/src/platform/state/default-global-state.ts rename libs/common/src/platform/{services => state}/default-user-state.provider.spec.ts (96%) create mode 100644 libs/common/src/platform/state/default-user-state.provider.ts rename libs/common/src/platform/{services/default-user-state.provider.ts => state/default-user-state.ts} (66%) rename libs/common/src/platform/{types => state}/derived-state-definition.ts (85%) create mode 100644 libs/common/src/platform/state/derived-user-state.ts create mode 100644 libs/common/src/platform/state/index.ts rename libs/common/src/platform/{types => state}/key-definition.ts (100%) create mode 100644 libs/common/src/platform/state/key-definitions.ts rename libs/common/src/platform/{types => state}/state-definition.ts (100%) rename libs/common/src/platform/{types => state}/state-definitions.spec.ts (100%) rename libs/common/src/platform/{types => state}/state-definitions.ts (100%) delete mode 100644 libs/common/src/vault/types/key-definitions.ts diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 7e10337acb3..cbbe1d32f50 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -92,12 +92,12 @@ import { ConsoleLogService } from "@bitwarden/common/platform/services/console-l import { CryptoService } from "@bitwarden/common/platform/services/crypto.service"; import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation"; import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation"; -import { DefaultUserStateProvider } from "@bitwarden/common/platform/services/default-user-state.provider"; import { EnvironmentService } from "@bitwarden/common/platform/services/environment.service"; import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service"; import { StateService } from "@bitwarden/common/platform/services/state.service"; import { ValidationService } from "@bitwarden/common/platform/services/validation.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; +import { DefaultUserStateProvider } from "@bitwarden/common/platform/state"; import { AvatarUpdateService } from "@bitwarden/common/services/account/avatar-update.service"; import { AnonymousHubService } from "@bitwarden/common/services/anonymousHub.service"; import { ApiService } from "@bitwarden/common/services/api.service"; diff --git a/libs/common/src/platform/abstractions/global-state.provider.ts b/libs/common/src/platform/abstractions/global-state.provider.ts index cb2f9195e11..6a27e487e4d 100644 --- a/libs/common/src/platform/abstractions/global-state.provider.ts +++ b/libs/common/src/platform/abstractions/global-state.provider.ts @@ -1,5 +1,5 @@ import { GlobalState } from "../interfaces/global-state"; -import { KeyDefinition } from "../types/key-definition"; +import { KeyDefinition } from "../state/key-definition"; export abstract class GlobalStateProvider { create: (keyDefinition: KeyDefinition) => GlobalState; diff --git a/libs/common/src/platform/abstractions/user-state.provider.ts b/libs/common/src/platform/abstractions/user-state.provider.ts index 8c2c2b4e363..5c37b89853b 100644 --- a/libs/common/src/platform/abstractions/user-state.provider.ts +++ b/libs/common/src/platform/abstractions/user-state.provider.ts @@ -1,5 +1,5 @@ import { UserState } from "../interfaces/user-state"; -import { KeyDefinition } from "../types/key-definition"; +import { KeyDefinition } from "../state/key-definition"; export abstract class UserStateProvider { create: (keyDefinition: KeyDefinition) => UserState; diff --git a/libs/common/src/platform/interfaces/user-state.ts b/libs/common/src/platform/interfaces/user-state.ts index 8963f78e7fa..f5583767e4e 100644 --- a/libs/common/src/platform/interfaces/user-state.ts +++ b/libs/common/src/platform/interfaces/user-state.ts @@ -1,8 +1,7 @@ import { Observable } from "rxjs"; import { UserId } from "../../types/guid"; -import { DerivedUserState } from "../services/default-user-state.provider"; -import { DerivedStateDefinition } from "../types/derived-state-definition"; +import { DerivedStateDefinition , DerivedUserState } from "../state/"; export interface UserState { readonly state$: Observable; diff --git a/libs/common/src/platform/misc/key-builders.ts b/libs/common/src/platform/misc/key-builders.ts index 92b0e8acf31..009dbfffa82 100644 --- a/libs/common/src/platform/misc/key-builders.ts +++ b/libs/common/src/platform/misc/key-builders.ts @@ -1,4 +1,4 @@ -import { KeyDefinition } from "../types/key-definition"; +import { KeyDefinition } from "../state/key-definition"; // TODO: Use Matts `UserId` type export function userKeyBuilder(userId: string, keyDefinition: KeyDefinition): string { diff --git a/libs/common/src/platform/services/default-global-state.provider.ts b/libs/common/src/platform/services/default-global-state.provider.ts deleted file mode 100644 index bce08afd756..00000000000 --- a/libs/common/src/platform/services/default-global-state.provider.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { BehaviorSubject, Observable } from "rxjs"; -import { Jsonify } from "type-fest"; - -import { GlobalStateProvider } from "../abstractions/global-state.provider"; -import { - AbstractMemoryStorageService, - AbstractStorageService, -} from "../abstractions/storage.service"; -import { GlobalState } from "../interfaces/global-state"; -import { globalKeyBuilder } from "../misc/key-builders"; -import { KeyDefinition } from "../types/key-definition"; - -// TODO: Move type -export type StorageLocation = "memory" | "disk" | "secure"; - -class GlobalStateImplementation implements GlobalState { - private storageKey: string; - private seededPromise: Promise; - - protected stateSubject: BehaviorSubject = new BehaviorSubject(null); - - state$: Observable; - - constructor( - private keyDefinition: KeyDefinition, - private chosenLocation: AbstractStorageService - ) { - this.storageKey = globalKeyBuilder(this.keyDefinition); - - this.seededPromise = this.chosenLocation.get>(this.storageKey).then((data) => { - const serializedData = this.keyDefinition.deserializer(data); - this.stateSubject.next(serializedData); - }); - - this.state$ = this.stateSubject.asObservable(); - } - - async update(configureState: (state: T) => void): Promise { - await this.seededPromise; - const currentState = this.stateSubject.getValue(); - configureState(currentState); - await this.chosenLocation.save(this.storageKey, currentState); - this.stateSubject.next(currentState); - } - - async getFromState(): Promise { - const data = await this.chosenLocation.get>(this.storageKey); - return this.keyDefinition.deserializer(data); - } -} - -export class DefaultGlobalStateProvider implements GlobalStateProvider { - private globalStateCache: Record> = {}; - - constructor( - private memoryStorage: AbstractMemoryStorageService, - private diskStorage: AbstractStorageService, - private secureStorage: AbstractStorageService - ) {} - - create(keyDefinition: KeyDefinition): GlobalState { - const locationDomainKey = `${keyDefinition.stateDefinition.storageLocation}_${keyDefinition.stateDefinition.name}_${keyDefinition.key}`; - const existingGlobalState = this.globalStateCache[locationDomainKey]; - if (existingGlobalState != null) { - // I have to cast out of the unknown generic but this should be safe if rules - // around domain token are made - return existingGlobalState as GlobalStateImplementation; - } - - const newGlobalState = new GlobalStateImplementation( - keyDefinition, - this.getLocation(keyDefinition.stateDefinition.storageLocation) - ); - - this.globalStateCache[locationDomainKey] = newGlobalState; - return newGlobalState; - } - - private getLocation(location: StorageLocation) { - switch (location) { - case "disk": - return this.diskStorage; - case "secure": - return this.secureStorage; - case "memory": - return this.memoryStorage; - } - } -} diff --git a/libs/common/src/platform/state/default-global-state.provider.ts b/libs/common/src/platform/state/default-global-state.provider.ts new file mode 100644 index 00000000000..aa69ace7970 --- /dev/null +++ b/libs/common/src/platform/state/default-global-state.provider.ts @@ -0,0 +1,49 @@ +import { GlobalStateProvider } from "../abstractions/global-state.provider"; +import { + AbstractMemoryStorageService, + AbstractStorageService, +} from "../abstractions/storage.service"; +import { GlobalState } from "../interfaces/global-state"; + +import { DefaultGlobalState } from "./default-global-state"; +import { KeyDefinition } from "./key-definition"; +import { StorageLocation } from "./state-definition"; + +export class DefaultGlobalStateProvider implements GlobalStateProvider { + private globalStateCache: Record> = {}; + + constructor( + private memoryStorage: AbstractMemoryStorageService, + private diskStorage: AbstractStorageService, + private secureStorage: AbstractStorageService + ) {} + + create(keyDefinition: KeyDefinition): GlobalState { + const locationDomainKey = `${keyDefinition.stateDefinition.storageLocation}_${keyDefinition.stateDefinition.name}_${keyDefinition.key}`; + const existingGlobalState = this.globalStateCache[locationDomainKey]; + if (existingGlobalState != null) { + // I have to cast out of the unknown generic but this should be safe if rules + // around domain token are made + return existingGlobalState as DefaultGlobalState; + } + + const newGlobalState = new DefaultGlobalState( + keyDefinition, + this.getLocation(keyDefinition.stateDefinition.storageLocation) + ); + + this.globalStateCache[locationDomainKey] = newGlobalState; + return newGlobalState; + } + + private getLocation(location: StorageLocation) { + switch (location) { + case "disk": + return this.diskStorage; + case "secure": + return this.secureStorage; + case "memory": + return this.memoryStorage; + } + } +} diff --git a/libs/common/src/platform/state/default-global-state.ts b/libs/common/src/platform/state/default-global-state.ts new file mode 100644 index 00000000000..8d8c989e032 --- /dev/null +++ b/libs/common/src/platform/state/default-global-state.ts @@ -0,0 +1,44 @@ +import { BehaviorSubject, Observable } from "rxjs"; +import { Jsonify } from "type-fest"; + +import { AbstractStorageService } from "../abstractions/storage.service"; +import { GlobalState } from "../interfaces/global-state"; +import { globalKeyBuilder } from "../misc/key-builders"; + +import { KeyDefinition } from "./key-definition"; + +export class DefaultGlobalState implements GlobalState { + private storageKey: string; + private seededPromise: Promise; + + protected stateSubject: BehaviorSubject = new BehaviorSubject(null); + + state$: Observable; + + constructor( + private keyDefinition: KeyDefinition, + private chosenLocation: AbstractStorageService + ) { + this.storageKey = globalKeyBuilder(this.keyDefinition); + + this.seededPromise = this.chosenLocation.get>(this.storageKey).then((data) => { + const serializedData = this.keyDefinition.deserializer(data); + this.stateSubject.next(serializedData); + }); + + this.state$ = this.stateSubject.asObservable(); + } + + async update(configureState: (state: T) => void): Promise { + await this.seededPromise; + const currentState = this.stateSubject.getValue(); + configureState(currentState); + await this.chosenLocation.save(this.storageKey, currentState); + this.stateSubject.next(currentState); + } + + async getFromState(): Promise { + const data = await this.chosenLocation.get>(this.storageKey); + return this.keyDefinition.deserializer(data); + } +} diff --git a/libs/common/src/platform/services/default-user-state.provider.spec.ts b/libs/common/src/platform/state/default-user-state.provider.spec.ts similarity index 96% rename from libs/common/src/platform/services/default-user-state.provider.spec.ts rename to libs/common/src/platform/state/default-user-state.provider.spec.ts index 664a93573ad..65951c55975 100644 --- a/libs/common/src/platform/services/default-user-state.provider.spec.ts +++ b/libs/common/src/platform/state/default-user-state.provider.spec.ts @@ -6,8 +6,8 @@ import { AccountInfo, AccountService } from "../../auth/abstractions/account.ser import { AuthenticationStatus } from "../../auth/enums/authentication-status"; import { UserId } from "../../types/guid"; import { AbstractMemoryStorageService } from "../abstractions/storage.service"; -import { KeyDefinition } from "../types/key-definition"; -import { StateDefinition } from "../types/state-definition"; +import { KeyDefinition } from "../state/key-definition"; +import { StateDefinition } from "../state/state-definition"; import { DefaultUserStateProvider } from "./default-user-state.provider"; diff --git a/libs/common/src/platform/state/default-user-state.provider.ts b/libs/common/src/platform/state/default-user-state.provider.ts new file mode 100644 index 00000000000..574db4c6dc8 --- /dev/null +++ b/libs/common/src/platform/state/default-user-state.provider.ts @@ -0,0 +1,42 @@ +import { AccountService } from "../../auth/abstractions/account.service"; +import { EncryptService } from "../abstractions/encrypt.service"; +import { + AbstractMemoryStorageService, + AbstractStorageService, +} from "../abstractions/storage.service"; +import { UserStateProvider } from "../abstractions/user-state.provider"; +import { DefaultUserState } from "../state/default-user-state"; +import { KeyDefinition } from "../state/key-definition"; + +export class DefaultUserStateProvider implements UserStateProvider { + private userStateCache: Record> = {}; + + constructor( + private accountService: AccountService, // Inject the lightest weight service that provides accountUserId$ + private encryptService: EncryptService, + private memoryStorage: AbstractMemoryStorageService, + private diskStorage: AbstractStorageService, + private secureStorage: AbstractStorageService + ) {} + + create(keyDefinition: KeyDefinition): DefaultUserState { + const locationDomainKey = `${keyDefinition.stateDefinition.storageLocation}_${keyDefinition.stateDefinition.name}_${keyDefinition.key}`; + const existingUserState = this.userStateCache[locationDomainKey]; + if (existingUserState != null) { + // I have to cast out of the unknown generic but this should be safe if rules + // around domain token are made + return existingUserState as DefaultUserState; + } + + const newUserState = new DefaultUserState( + keyDefinition, + this.accountService, + this.encryptService, + this.memoryStorage, + this.secureStorage, + this.diskStorage + ); + this.userStateCache[locationDomainKey] = newUserState; + return newUserState; + } +} diff --git a/libs/common/src/platform/services/default-user-state.provider.ts b/libs/common/src/platform/state/default-user-state.ts similarity index 66% rename from libs/common/src/platform/services/default-user-state.provider.ts rename to libs/common/src/platform/state/default-user-state.ts index 4396a563447..5ca461ab06a 100644 --- a/libs/common/src/platform/services/default-user-state.provider.ts +++ b/libs/common/src/platform/state/default-user-state.ts @@ -1,13 +1,13 @@ import { - BehaviorSubject, Observable, - defer, - firstValueFrom, + BehaviorSubject, map, - share, shareReplay, switchMap, tap, + share, + defer, + firstValueFrom, } from "rxjs"; import { Jsonify } from "type-fest"; @@ -15,52 +15,18 @@ import { AccountService } from "../../auth/abstractions/account.service"; import { UserId } from "../../types/guid"; import { EncryptService } from "../abstractions/encrypt.service"; import { - AbstractMemoryStorageService, AbstractStorageService, + AbstractMemoryStorageService, } from "../abstractions/storage.service"; -import { UserStateProvider } from "../abstractions/user-state.provider"; import { UserState } from "../interfaces/user-state"; import { userKeyBuilder } from "../misc/key-builders"; -import { DeriveContext, DerivedStateDefinition } from "../types/derived-state-definition"; -import { KeyDefinition } from "../types/key-definition"; -import { StorageLocation } from "./default-global-state.provider"; +import { DerivedStateDefinition } from "./derived-state-definition"; +import { DerivedUserState } from "./derived-user-state"; +import { KeyDefinition } from "./key-definition"; +import { StorageLocation } from "./state-definition"; -export class DerivedUserState { - state$: Observable; - - // TODO: Probably needs to take state service - /** - * - */ - constructor( - private derivedStateDefinition: DerivedStateDefinition, - private encryptService: EncryptService, - private userState: UserState - ) { - this.state$ = userState.state$.pipe( - switchMap(async (from) => { - // TODO: How do I get the key? - const convertedData = await derivedStateDefinition.converter( - from, - new DeriveContext(null, encryptService) - ); - return convertedData; - }) - ); - } - - async getFromState(): Promise { - const encryptedFromState = await this.userState.getFromState(); - - const context = new DeriveContext(null, this.encryptService); - - const decryptedData = await this.derivedStateDefinition.converter(encryptedFromState, context); - return decryptedData; - } -} - -class DefaultUserState implements UserState { +export class DefaultUserState implements UserState { private seededInitial = false; private formattedKey$: Observable; @@ -192,36 +158,3 @@ class DefaultUserState implements UserState { } } } - -export class DefaultUserStateProvider implements UserStateProvider { - private userStateCache: Record> = {}; - - constructor( - private accountService: AccountService, // Inject the lightest weight service that provides accountUserId$ - private encryptService: EncryptService, - private memoryStorage: AbstractMemoryStorageService, - private diskStorage: AbstractStorageService, - private secureStorage: AbstractStorageService - ) {} - - create(keyDefinition: KeyDefinition): DefaultUserState { - const locationDomainKey = `${keyDefinition.stateDefinition.storageLocation}_${keyDefinition.stateDefinition.name}_${keyDefinition.key}`; - const existingUserState = this.userStateCache[locationDomainKey]; - if (existingUserState != null) { - // I have to cast out of the unknown generic but this should be safe if rules - // around domain token are made - return existingUserState as DefaultUserState; - } - - const newUserState = new DefaultUserState( - keyDefinition, - this.accountService, - this.encryptService, - this.memoryStorage, - this.secureStorage, - this.diskStorage - ); - this.userStateCache[locationDomainKey] = newUserState; - return newUserState; - } -} diff --git a/libs/common/src/platform/types/derived-state-definition.ts b/libs/common/src/platform/state/derived-state-definition.ts similarity index 85% rename from libs/common/src/platform/types/derived-state-definition.ts rename to libs/common/src/platform/state/derived-state-definition.ts index 3b525ad25eb..bed82011929 100644 --- a/libs/common/src/platform/types/derived-state-definition.ts +++ b/libs/common/src/platform/state/derived-state-definition.ts @@ -1,6 +1,7 @@ import { EncryptService } from "../abstractions/encrypt.service"; import { UserKey } from "../models/domain/symmetric-crypto-key"; -import { StorageLocation } from "../services/default-global-state.provider"; + +import { StorageLocation } from "./state-definition"; // TODO: Move type export class DeriveContext { diff --git a/libs/common/src/platform/state/derived-user-state.ts b/libs/common/src/platform/state/derived-user-state.ts new file mode 100644 index 00000000000..cd59389c88f --- /dev/null +++ b/libs/common/src/platform/state/derived-user-state.ts @@ -0,0 +1,40 @@ +import { Observable, switchMap } from "rxjs"; + +import { EncryptService } from "../abstractions/encrypt.service"; +import { UserState } from "../interfaces/user-state"; + +import { DerivedStateDefinition, DeriveContext } from "./derived-state-definition"; + +export class DerivedUserState { + state$: Observable; + + // TODO: Probably needs to take state service + /** + * + */ + constructor( + private derivedStateDefinition: DerivedStateDefinition, + private encryptService: EncryptService, + private userState: UserState + ) { + this.state$ = userState.state$.pipe( + switchMap(async (from) => { + // TODO: How do I get the key? + const convertedData = await derivedStateDefinition.converter( + from, + new DeriveContext(null, encryptService) + ); + return convertedData; + }) + ); + } + + async getFromState(): Promise { + const encryptedFromState = await this.userState.getFromState(); + + const context = new DeriveContext(null, this.encryptService); + + const decryptedData = await this.derivedStateDefinition.converter(encryptedFromState, context); + return decryptedData; + } +} diff --git a/libs/common/src/platform/state/index.ts b/libs/common/src/platform/state/index.ts new file mode 100644 index 00000000000..61dc7fffb3b --- /dev/null +++ b/libs/common/src/platform/state/index.ts @@ -0,0 +1,13 @@ +// Export all established state definitions +export * from "./state-definitions"; +// Export all established KeyDefinitions +export * from "./key-definitions"; +export { DefaultGlobalStateProvider } from "./default-global-state.provider"; +export { DefaultGlobalState } from "./default-global-state"; +export { DefaultUserStateProvider } from "./default-user-state.provider"; +export { DefaultUserState } from "./default-user-state"; +export { DerivedStateDefinition } from "./derived-state-definition"; +export { DerivedUserState } from "./derived-user-state"; +// TODO: should this be exported? +export { KeyDefinition } from "./key-definition"; +export { StorageLocation } from "./state-definition"; diff --git a/libs/common/src/platform/types/key-definition.ts b/libs/common/src/platform/state/key-definition.ts similarity index 100% rename from libs/common/src/platform/types/key-definition.ts rename to libs/common/src/platform/state/key-definition.ts diff --git a/libs/common/src/platform/state/key-definitions.ts b/libs/common/src/platform/state/key-definitions.ts new file mode 100644 index 00000000000..be97432943f --- /dev/null +++ b/libs/common/src/platform/state/key-definitions.ts @@ -0,0 +1,11 @@ +import { FolderData } from "../../vault/models/data/folder.data"; + +import { KeyDefinition } from "./key-definition"; +import { FOLDER_SERVICE_DISK } from "./state-definitions"; + +// FolderService Keys +export const FOLDERS = KeyDefinition.record( + FOLDER_SERVICE_DISK, + "folders", + FolderData.fromJSON +); diff --git a/libs/common/src/platform/types/state-definition.ts b/libs/common/src/platform/state/state-definition.ts similarity index 100% rename from libs/common/src/platform/types/state-definition.ts rename to libs/common/src/platform/state/state-definition.ts diff --git a/libs/common/src/platform/types/state-definitions.spec.ts b/libs/common/src/platform/state/state-definitions.spec.ts similarity index 100% rename from libs/common/src/platform/types/state-definitions.spec.ts rename to libs/common/src/platform/state/state-definitions.spec.ts diff --git a/libs/common/src/platform/types/state-definitions.ts b/libs/common/src/platform/state/state-definitions.ts similarity index 100% rename from libs/common/src/platform/types/state-definitions.ts rename to libs/common/src/platform/state/state-definitions.ts diff --git a/libs/common/src/state-migrations/migrations/9-move-folder-to-owned.ts b/libs/common/src/state-migrations/migrations/9-move-folder-to-owned.ts index a861c0a2440..191333ea415 100644 --- a/libs/common/src/state-migrations/migrations/9-move-folder-to-owned.ts +++ b/libs/common/src/state-migrations/migrations/9-move-folder-to-owned.ts @@ -3,10 +3,10 @@ import { userKeyBuilder } from "../../platform/misc/key-builders"; // TODO: Add message // eslint-disable-next-line import/no-restricted-paths -import { KeyDefinition } from "../../platform/types/key-definition"; +import { KeyDefinition } from "../../platform/state/key-definition"; // TODO: Add message // eslint-disable-next-line import/no-restricted-paths -import { StateDefinition } from "../../platform/types/state-definition"; +import { StateDefinition } from "../../platform/state/state-definition"; import { MigrationHelper } from "../migration-helper"; import { IRREVERSIBLE, Migrator } from "../migrator"; diff --git a/libs/common/src/vault/services/folder/folder.service.ts b/libs/common/src/vault/services/folder/folder.service.ts index 3da854faca2..dae1f4b4883 100644 --- a/libs/common/src/vault/services/folder/folder.service.ts +++ b/libs/common/src/vault/services/folder/folder.service.ts @@ -7,7 +7,8 @@ import { UserStateProvider } from "../../../platform/abstractions/user-state.pro import { UserState } from "../../../platform/interfaces/user-state"; import { Utils } from "../../../platform/misc/utils"; import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key"; -import { DerivedUserState } from "../../../platform/services/default-user-state.provider"; +import { DerivedUserState } from "../../../platform/state"; +import { FOLDERS } from "../../../platform/state/key-definitions"; import { UserId } from "../../../types/guid"; import { CipherService } from "../../../vault/abstractions/cipher.service"; import { InternalFolderService as InternalFolderServiceAbstraction } from "../../../vault/abstractions/folder/folder.service.abstraction"; @@ -15,7 +16,6 @@ import { CipherData } from "../../../vault/models/data/cipher.data"; import { FolderData } from "../../../vault/models/data/folder.data"; import { Folder } from "../../../vault/models/domain/folder"; import { FolderView } from "../../../vault/models/view/folder.view"; -import { FOLDERS } from "../../types/key-definitions"; export class FolderService implements InternalFolderServiceAbstraction { folderState: UserState>; diff --git a/libs/common/src/vault/types/key-definitions.ts b/libs/common/src/vault/types/key-definitions.ts deleted file mode 100644 index 61f21d71274..00000000000 --- a/libs/common/src/vault/types/key-definitions.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { KeyDefinition } from "../../platform/types/key-definition"; -import { FOLDER_SERVICE_DISK } from "../../platform/types/state-definitions"; -import { FolderData } from "../models/data/folder.data"; - -// FolderService Keys -export const FOLDERS = KeyDefinition.record( - FOLDER_SERVICE_DISK, - "folders", - FolderData.fromJSON -);