From 2819ac597f6f7ee25085eea33b0089ad2f1d1330 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Mon, 5 Aug 2024 11:39:08 -0400 Subject: [PATCH] [BEEEP: PM-10190] Use strict TS checks in CLI service container (#10298) * move cli service-container to new folder * fix imports * add tsconfig and fix type issues in other services * fix more imports in service-container * make ts server happy in service-container * fix actual bugs in cli service-container * fix package json reference path * fix service-container import * update type on cipher service --- apps/cli/src/base-program.ts | 2 +- apps/cli/src/bw.ts | 2 +- apps/cli/src/commands/serve.command.ts | 2 +- apps/cli/src/oss-serve-configurator.ts | 2 +- apps/cli/src/register-oss-programs.ts | 2 +- apps/cli/src/serve.program.ts | 2 +- .../service-container.spec.ts | 0 .../service-container.ts | 102 ++++++++++-------- apps/cli/src/service-container/tsconfig.json | 7 ++ .../bit-cli/src/service-container.ts | 2 +- .../user-decryption-options.service.ts | 8 +- .../policy/policy-api.service.abstraction.ts | 4 +- .../organization/organization.service.ts | 6 +- .../services/policy/policy.service.ts | 2 +- .../src/auth/abstractions/account.service.ts | 2 +- .../src/auth/services/account.service.ts | 23 ++-- .../auth/services/key-connector.service.ts | 3 +- .../src/platform/services/crypto.service.ts | 4 +- .../services/default-environment.service.ts | 2 +- .../src/vault/abstractions/cipher.service.ts | 2 +- .../vault/abstractions/collection.service.ts | 2 +- .../folder/folder.service.abstraction.ts | 4 +- .../src/vault/services/cipher.service.ts | 4 +- .../src/vault/services/collection.service.ts | 2 +- 24 files changed, 110 insertions(+), 81 deletions(-) rename apps/cli/src/{ => service-container}/service-container.spec.ts (100%) rename apps/cli/src/{ => service-container}/service-container.ts (96%) create mode 100644 apps/cli/src/service-container/tsconfig.json diff --git a/apps/cli/src/base-program.ts b/apps/cli/src/base-program.ts index 563b205fa7..f308bdc2de 100644 --- a/apps/cli/src/base-program.ts +++ b/apps/cli/src/base-program.ts @@ -10,7 +10,7 @@ import { ListResponse } from "./models/response/list.response"; import { MessageResponse } from "./models/response/message.response"; import { StringResponse } from "./models/response/string.response"; import { TemplateResponse } from "./models/response/template.response"; -import { ServiceContainer } from "./service-container"; +import { ServiceContainer } from "./service-container/service-container"; import { CliUtils } from "./utils"; const writeLn = CliUtils.writeLn; diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index e4c46dd9ee..5e9d3dfbc9 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -3,7 +3,7 @@ import { program } from "commander"; import { OssServeConfigurator } from "./oss-serve-configurator"; import { registerOssPrograms } from "./register-oss-programs"; import { ServeProgram } from "./serve.program"; -import { ServiceContainer } from "./service-container"; +import { ServiceContainer } from "./service-container/service-container"; async function main() { const serviceContainer = new ServiceContainer(); diff --git a/apps/cli/src/commands/serve.command.ts b/apps/cli/src/commands/serve.command.ts index 05603a3c24..801f505f1a 100644 --- a/apps/cli/src/commands/serve.command.ts +++ b/apps/cli/src/commands/serve.command.ts @@ -7,7 +7,7 @@ import * as koaJson from "koa-json"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { OssServeConfigurator } from "../oss-serve-configurator"; -import { ServiceContainer } from "../service-container"; +import { ServiceContainer } from "../service-container/service-container"; export class ServeCommand { constructor( diff --git a/apps/cli/src/oss-serve-configurator.ts b/apps/cli/src/oss-serve-configurator.ts index 13f50da78b..8a38f8f128 100644 --- a/apps/cli/src/oss-serve-configurator.ts +++ b/apps/cli/src/oss-serve-configurator.ts @@ -13,7 +13,7 @@ import { RestoreCommand } from "./commands/restore.command"; import { StatusCommand } from "./commands/status.command"; import { Response } from "./models/response"; import { FileResponse } from "./models/response/file.response"; -import { ServiceContainer } from "./service-container"; +import { ServiceContainer } from "./service-container/service-container"; import { GenerateCommand } from "./tools/generate.command"; import { SendEditCommand, diff --git a/apps/cli/src/register-oss-programs.ts b/apps/cli/src/register-oss-programs.ts index d8aa54118d..1fc1f0119d 100644 --- a/apps/cli/src/register-oss-programs.ts +++ b/apps/cli/src/register-oss-programs.ts @@ -1,5 +1,5 @@ import { Program } from "./program"; -import { ServiceContainer } from "./service-container"; +import { ServiceContainer } from "./service-container/service-container"; import { SendProgram } from "./tools/send/send.program"; import { VaultProgram } from "./vault.program"; diff --git a/apps/cli/src/serve.program.ts b/apps/cli/src/serve.program.ts index bbf66661e5..ef18a3e35c 100644 --- a/apps/cli/src/serve.program.ts +++ b/apps/cli/src/serve.program.ts @@ -3,7 +3,7 @@ import { program } from "commander"; import { BaseProgram } from "./base-program"; import { ServeCommand } from "./commands/serve.command"; import { OssServeConfigurator } from "./oss-serve-configurator"; -import { ServiceContainer } from "./service-container"; +import { ServiceContainer } from "./service-container/service-container"; import { CliUtils } from "./utils"; const writeLn = CliUtils.writeLn; diff --git a/apps/cli/src/service-container.spec.ts b/apps/cli/src/service-container/service-container.spec.ts similarity index 100% rename from apps/cli/src/service-container.spec.ts rename to apps/cli/src/service-container/service-container.spec.ts diff --git a/apps/cli/src/service-container.ts b/apps/cli/src/service-container/service-container.ts similarity index 96% rename from apps/cli/src/service-container.ts rename to apps/cli/src/service-container/service-container.ts index 8ee99fa203..d35412ede3 100644 --- a/apps/cli/src/service-container.ts +++ b/apps/cli/src/service-container/service-container.ts @@ -44,7 +44,10 @@ import { TokenService } from "@bitwarden/common/auth/services/token.service"; import { TwoFactorService } from "@bitwarden/common/auth/services/two-factor.service"; import { UserVerificationApiService } from "@bitwarden/common/auth/services/user-verification/user-verification-api.service"; import { UserVerificationService } from "@bitwarden/common/auth/services/user-verification/user-verification.service"; -import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service"; +import { + AutofillSettingsService, + AutofillSettingsServiceAbstraction, +} from "@bitwarden/common/autofill/services/autofill-settings.service"; import { DefaultDomainSettingsService, DomainSettingsService, @@ -147,18 +150,18 @@ import { VaultExportServiceAbstraction, } from "@bitwarden/vault-export-core"; -import { CliPlatformUtilsService } from "./platform/services/cli-platform-utils.service"; -import { ConsoleLogService } from "./platform/services/console-log.service"; -import { I18nService } from "./platform/services/i18n.service"; -import { LowdbStorageService } from "./platform/services/lowdb-storage.service"; -import { NodeApiService } from "./platform/services/node-api.service"; -import { NodeEnvSecureStorageService } from "./platform/services/node-env-secure-storage.service"; +import { CliPlatformUtilsService } from "../platform/services/cli-platform-utils.service"; +import { ConsoleLogService } from "../platform/services/console-log.service"; +import { I18nService } from "../platform/services/i18n.service"; +import { LowdbStorageService } from "../platform/services/lowdb-storage.service"; +import { NodeApiService } from "../platform/services/node-api.service"; +import { NodeEnvSecureStorageService } from "../platform/services/node-env-secure-storage.service"; // Polyfills global.DOMParser = new jsdom.JSDOM().window.DOMParser; // eslint-disable-next-line -const packageJson = require("../package.json"); +const packageJson = require("../../package.json"); /** * Instantiates services and makes them available for dependency injection. @@ -254,13 +257,13 @@ export class ServiceContainer { } else if (process.env.BITWARDENCLI_APPDATA_DIR) { p = path.resolve(process.env.BITWARDENCLI_APPDATA_DIR); } else if (process.platform === "darwin") { - p = path.join(process.env.HOME, "Library/Application Support/Bitwarden CLI"); + p = path.join(process.env.HOME ?? "", "Library/Application Support/Bitwarden CLI"); } else if (process.platform === "win32") { - p = path.join(process.env.APPDATA, "Bitwarden CLI"); + p = path.join(process.env.APPDATA ?? "", "Bitwarden CLI"); } else if (process.env.XDG_CONFIG_HOME) { p = path.join(process.env.XDG_CONFIG_HOME, "Bitwarden CLI"); } else { - p = path.join(process.env.HOME, ".config/Bitwarden CLI"); + p = path.join(process.env.HOME ?? "", ".config/Bitwarden CLI"); } const logoutCallback = async () => await this.logout(); @@ -452,8 +455,6 @@ export class ServiceContainer { customUserAgent, ); - this.organizationApiService = new OrganizationApiService(this.apiService, this.syncService); - this.containerService = new ContainerService(this.cryptoService, this.encryptService); this.domainSettingsService = new DefaultDomainSettingsService(this.stateProvider); @@ -524,6 +525,40 @@ export class ServiceContainer { this.stateProvider, ); + this.authRequestService = new AuthRequestService( + this.appIdService, + this.accountService, + this.masterPasswordService, + this.cryptoService, + this.apiService, + this.stateProvider, + ); + + this.billingAccountProfileStateService = new DefaultBillingAccountProfileStateService( + this.stateProvider, + ); + + this.taskSchedulerService = new DefaultTaskSchedulerService(this.logService); + + this.authService = new AuthService( + this.accountService, + this.messagingService, + this.cryptoService, + this.apiService, + this.stateService, + this.tokenService, + ); + + this.configApiService = new ConfigApiService(this.apiService, this.tokenService); + + this.configService = new DefaultConfigService( + this.configApiService, + this.environmentService, + this.logService, + this.stateProvider, + this.authService, + ); + this.devicesApiService = new DevicesApiServiceImplementation(this.apiService); this.deviceTrustService = new DeviceTrustService( this.keyGenerationService, @@ -541,20 +576,6 @@ export class ServiceContainer { this.configService, ); - this.authRequestService = new AuthRequestService( - this.appIdService, - this.accountService, - this.masterPasswordService, - this.cryptoService, - this.apiService, - this.stateProvider, - ); - - this.billingAccountProfileStateService = new DefaultBillingAccountProfileStateService( - this.stateProvider, - ); - - this.taskSchedulerService = new DefaultTaskSchedulerService(this.logService); this.loginStrategyService = new LoginStrategyService( this.accountService, this.masterPasswordService, @@ -583,23 +604,10 @@ export class ServiceContainer { this.taskSchedulerService, ); - this.authService = new AuthService( - this.accountService, - this.messagingService, - this.cryptoService, - this.apiService, - this.stateService, - this.tokenService, - ); - - this.configApiService = new ConfigApiService(this.apiService, this.tokenService); - - this.configService = new DefaultConfigService( - this.configApiService, - this.environmentService, - this.logService, + // FIXME: CLI does not support autofill + this.autofillSettingsService = new AutofillSettingsService( this.stateProvider, - this.authService, + this.policyService, ); this.cipherService = new CipherService( @@ -661,7 +669,7 @@ export class ServiceContainer { this.taskSchedulerService, this.logService, lockedCallback, - null, + undefined, ); this.avatarService = new AvatarService(this.apiService, this.stateProvider); @@ -752,6 +760,8 @@ export class ServiceContainer { this.accountService, ); + this.organizationApiService = new OrganizationApiService(this.apiService, this.syncService); + this.providerApiService = new ProviderApiService(this.apiService); } @@ -774,7 +784,7 @@ export class ServiceContainer { await this.stateService.clean(); await this.accountService.clean(userId); await this.accountService.switchAccount(null); - process.env.BW_SESSION = null; + process.env.BW_SESSION = undefined; } async init() { @@ -790,7 +800,7 @@ export class ServiceContainer { this.twoFactorService.init(); const activeAccount = await firstValueFrom(this.accountService.activeAccount$); - if (activeAccount) { + if (activeAccount?.id) { await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(activeAccount.id); } diff --git a/apps/cli/src/service-container/tsconfig.json b/apps/cli/src/service-container/tsconfig.json new file mode 100644 index 0000000000..ee24d230ae --- /dev/null +++ b/apps/cli/src/service-container/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "strictNullChecks": true, + "strictPropertyInitialization": true + } +} diff --git a/bitwarden_license/bit-cli/src/service-container.ts b/bitwarden_license/bit-cli/src/service-container.ts index 995e14531d..0238829a13 100644 --- a/bitwarden_license/bit-cli/src/service-container.ts +++ b/bitwarden_license/bit-cli/src/service-container.ts @@ -2,7 +2,7 @@ import { OrganizationAuthRequestService, OrganizationAuthRequestApiService, } from "@bitwarden/bit-common/admin-console/auth-requests"; -import { ServiceContainer as OssServiceContainer } from "@bitwarden/cli/service-container"; +import { ServiceContainer as OssServiceContainer } from "@bitwarden/cli/service-container/service-container"; /** * Instantiates services and makes them available for dependency injection. diff --git a/libs/auth/src/common/services/user-decryption-options/user-decryption-options.service.ts b/libs/auth/src/common/services/user-decryption-options/user-decryption-options.service.ts index 6651ffd9e5..e4200c759e 100644 --- a/libs/auth/src/common/services/user-decryption-options/user-decryption-options.service.ts +++ b/libs/auth/src/common/services/user-decryption-options/user-decryption-options.service.ts @@ -1,4 +1,4 @@ -import { map } from "rxjs"; +import { Observable, map } from "rxjs"; import { ActiveUserState, @@ -25,8 +25,8 @@ export class UserDecryptionOptionsService { private userDecryptionOptionsState: ActiveUserState; - userDecryptionOptions$; - hasMasterPassword$; + userDecryptionOptions$: Observable; + hasMasterPassword$: Observable; constructor(private stateProvider: StateProvider) { this.userDecryptionOptionsState = this.stateProvider.getActive(USER_DECRYPTION_OPTIONS); @@ -37,7 +37,7 @@ export class UserDecryptionOptionsService ); } - userDecryptionOptionsById$(userId: UserId) { + userDecryptionOptionsById$(userId: UserId): Observable { return this.stateProvider.getUser(userId, USER_DECRYPTION_OPTIONS).state$; } diff --git a/libs/common/src/admin-console/abstractions/policy/policy-api.service.abstraction.ts b/libs/common/src/admin-console/abstractions/policy/policy-api.service.abstraction.ts index c601aad060..c7fec8813c 100644 --- a/libs/common/src/admin-console/abstractions/policy/policy-api.service.abstraction.ts +++ b/libs/common/src/admin-console/abstractions/policy/policy-api.service.abstraction.ts @@ -16,6 +16,8 @@ export class PolicyApiServiceAbstraction { organizationUserId: string, ) => Promise; - getMasterPasswordPolicyOptsForOrgUser: (orgId: string) => Promise; + getMasterPasswordPolicyOptsForOrgUser: ( + orgId: string, + ) => Promise; putPolicy: (organizationId: string, type: PolicyType, request: PolicyRequest) => Promise; } diff --git a/libs/common/src/admin-console/services/organization/organization.service.ts b/libs/common/src/admin-console/services/organization/organization.service.ts index 7013863c5c..d8fe18dc5c 100644 --- a/libs/common/src/admin-console/services/organization/organization.service.ts +++ b/libs/common/src/admin-console/services/organization/organization.service.ts @@ -64,8 +64,10 @@ function mapToSingleOrganization(organizationId: string) { } export class OrganizationService implements InternalOrganizationServiceAbstraction { - organizations$ = this.getOrganizationsFromState$(); - memberOrganizations$ = this.organizations$.pipe(mapToExcludeProviderOrganizations()); + organizations$: Observable = this.getOrganizationsFromState$(); + memberOrganizations$: Observable = this.organizations$.pipe( + mapToExcludeProviderOrganizations(), + ); constructor(private stateProvider: StateProvider) {} diff --git a/libs/common/src/admin-console/services/policy/policy.service.ts b/libs/common/src/admin-console/services/policy/policy.service.ts index 7ec525f960..2287ef9b4f 100644 --- a/libs/common/src/admin-console/services/policy/policy.service.ts +++ b/libs/common/src/admin-console/services/policy/policy.service.ts @@ -32,7 +32,7 @@ export class PolicyService implements InternalPolicyServiceAbstraction { private organizationService: OrganizationService, ) {} - get$(policyType: PolicyType) { + get$(policyType: PolicyType): Observable { const filteredPolicies$ = this.activeUserPolicies$.pipe( map((policies) => policies.filter((p) => p.type === policyType)), ); diff --git a/libs/common/src/auth/abstractions/account.service.ts b/libs/common/src/auth/abstractions/account.service.ts index b7fd6d9bb9..849abc65f6 100644 --- a/libs/common/src/auth/abstractions/account.service.ts +++ b/libs/common/src/auth/abstractions/account.service.ts @@ -72,7 +72,7 @@ export abstract class AccountService { * Updates the `activeAccount$` observable with the new active account. * @param userId */ - abstract switchAccount(userId: UserId): Promise; + abstract switchAccount(userId: UserId | null): Promise; /** * Cleans personal information for the given account from the `accounts$` observable. Does not remove the userId from the observable. * diff --git a/libs/common/src/auth/services/account.service.ts b/libs/common/src/auth/services/account.service.ts index 8af06b89e7..dceec2cbf1 100644 --- a/libs/common/src/auth/services/account.service.ts +++ b/libs/common/src/auth/services/account.service.ts @@ -1,4 +1,11 @@ -import { combineLatestWith, map, distinctUntilChanged, shareReplay, combineLatest } from "rxjs"; +import { + combineLatestWith, + map, + distinctUntilChanged, + shareReplay, + combineLatest, + Observable, +} from "rxjs"; import { AccountInfo, @@ -42,11 +49,11 @@ export class AccountServiceImplementation implements InternalAccountService { private accountsState: GlobalState>; private activeAccountIdState: GlobalState; - accounts$; - activeAccount$; - accountActivity$; - sortedUserIds$; - nextUpAccount$; + accounts$: Observable>; + activeAccount$: Observable<{ id: UserId | undefined } & AccountInfo>; + accountActivity$: Observable>; + sortedUserIds$: Observable; + nextUpAccount$: Observable<{ id: UserId } & AccountInfo>; constructor( private messagingService: MessagingService, @@ -61,7 +68,7 @@ export class AccountServiceImplementation implements InternalAccountService { ); this.activeAccount$ = this.activeAccountIdState.state$.pipe( combineLatestWith(this.accounts$), - map(([id, accounts]) => (id ? { id, ...accounts[id] } : undefined)), + map(([id, accounts]) => (id ? { id, ...(accounts[id] as AccountInfo) } : undefined)), distinctUntilChanged((a, b) => a?.id === b?.id && accountInfoEqual(a, b)), shareReplay({ bufferSize: 1, refCount: false }), ); @@ -118,7 +125,7 @@ export class AccountServiceImplementation implements InternalAccountService { await this.removeAccountActivity(userId); } - async switchAccount(userId: UserId): Promise { + async switchAccount(userId: UserId | null): Promise { let updateActivity = false; await this.activeAccountIdState.update( (_, accounts) => { diff --git a/libs/common/src/auth/services/key-connector.service.ts b/libs/common/src/auth/services/key-connector.service.ts index a70bbb6ffb..8f204e557e 100644 --- a/libs/common/src/auth/services/key-connector.service.ts +++ b/libs/common/src/auth/services/key-connector.service.ts @@ -5,6 +5,7 @@ import { LogoutReason } from "@bitwarden/auth/common"; import { ApiService } from "../../abstractions/api.service"; import { OrganizationService } from "../../admin-console/abstractions/organization/organization.service.abstraction"; import { OrganizationUserType } from "../../admin-console/enums"; +import { Organization } from "../../admin-console/models/domain/organization"; import { KeysRequest } from "../../models/request/keys.request"; import { CryptoService } from "../../platform/abstractions/crypto.service"; import { KeyGenerationService } from "../../platform/abstractions/key-generation.service"; @@ -114,7 +115,7 @@ export class KeyConnectorService implements KeyConnectorServiceAbstraction { } } - async getManagingOrganization() { + async getManagingOrganization(): Promise { const orgs = await this.organizationService.getAll(); return orgs.find( (o) => diff --git a/libs/common/src/platform/services/crypto.service.ts b/libs/common/src/platform/services/crypto.service.ts index 4d8a447576..b139775ea4 100644 --- a/libs/common/src/platform/services/crypto.service.ts +++ b/libs/common/src/platform/services/crypto.service.ts @@ -888,7 +888,7 @@ export class CryptoService implements CryptoServiceAbstraction { return this.encryptService.decryptToBytes(encBuffer, key); } - userKey$(userId: UserId) { + userKey$(userId: UserId): Observable { return this.stateProvider.getUser(userId, USER_KEY).state$; } @@ -1013,7 +1013,7 @@ export class CryptoService implements CryptoServiceAbstraction { ); } - orgKeys$(userId: UserId) { + orgKeys$(userId: UserId): Observable | null> { return this.cipherDecryptionKeys$(userId, true).pipe(map((keys) => keys?.orgKeys)); } diff --git a/libs/common/src/platform/services/default-environment.service.ts b/libs/common/src/platform/services/default-environment.service.ts index 59956ede7a..97f084d80f 100644 --- a/libs/common/src/platform/services/default-environment.service.ts +++ b/libs/common/src/platform/services/default-environment.service.ts @@ -269,7 +269,7 @@ export class DefaultEnvironmentService implements EnvironmentService { } } - async getEnvironment(userId?: UserId) { + async getEnvironment(userId?: UserId): Promise { if (userId == null) { return await firstValueFrom(this.environment$); } diff --git a/libs/common/src/vault/abstractions/cipher.service.ts b/libs/common/src/vault/abstractions/cipher.service.ts index ad4a08c2fe..83bdf016ed 100644 --- a/libs/common/src/vault/abstractions/cipher.service.ts +++ b/libs/common/src/vault/abstractions/cipher.service.ts @@ -129,7 +129,7 @@ export abstract class CipherService implements UserKeyRotationDataProvider Promise>; replace: (ciphers: { [id: string]: CipherData }) => Promise; - clear: (userId: string) => Promise; + clear: (userId?: string) => Promise; moveManyWithServer: (ids: string[], folderId: string) => Promise; delete: (id: string | string[]) => Promise; deleteWithServer: (id: string, asAdmin?: boolean) => Promise; diff --git a/libs/common/src/vault/abstractions/collection.service.ts b/libs/common/src/vault/abstractions/collection.service.ts index 87ce8edf43..0c20613963 100644 --- a/libs/common/src/vault/abstractions/collection.service.ts +++ b/libs/common/src/vault/abstractions/collection.service.ts @@ -23,6 +23,6 @@ export abstract class CollectionService { getNested: (id: string) => Promise>; upsert: (collection: CollectionData | CollectionData[]) => Promise; replace: (collections: { [id: string]: CollectionData }) => Promise; - clear: (userId: string) => Promise; + clear: (userId?: string) => Promise; delete: (id: string | string[]) => Promise; } diff --git a/libs/common/src/vault/abstractions/folder/folder.service.abstraction.ts b/libs/common/src/vault/abstractions/folder/folder.service.abstraction.ts index c22eb1febb..71b8089fa6 100644 --- a/libs/common/src/vault/abstractions/folder/folder.service.abstraction.ts +++ b/libs/common/src/vault/abstractions/folder/folder.service.abstraction.ts @@ -17,7 +17,7 @@ export abstract class FolderService implements UserKeyRotationDataProvider Promise; encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise; get: (id: string) => Promise; - getDecrypted$: (id: string) => Observable; + getDecrypted$: (id: string) => Observable; getAllFromState: () => Promise; /** * @deprecated Only use in CLI! @@ -46,6 +46,6 @@ export abstract class FolderService implements UserKeyRotationDataProvider Promise; replace: (folders: { [id: string]: FolderData }) => Promise; - clear: (userId: string) => Promise; + clear: (userId?: string) => Promise; delete: (id: string | string[]) => Promise; } diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 374f66c42e..3eeac75db0 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -571,7 +571,7 @@ export class CipherService implements CipherServiceAbstraction { return this.sortedCiphersCache.getNext(cacheKey); } - async getNextIdentityCipher() { + async getNextIdentityCipher(): Promise { const cacheKey = "identityCiphers"; if (!this.sortedCiphersCache.isCached(cacheKey)) { @@ -926,7 +926,7 @@ export class CipherService implements CipherServiceAbstraction { return updatedCiphers; } - async clear(userId?: UserId): Promise { + async clear(userId?: UserId): Promise { userId ??= await firstValueFrom(this.stateProvider.activeUserId$); await this.clearEncryptedCiphersState(userId); await this.clearCache(userId); diff --git a/libs/common/src/vault/services/collection.service.ts b/libs/common/src/vault/services/collection.service.ts index 096edb77f9..47063aa29d 100644 --- a/libs/common/src/vault/services/collection.service.ts +++ b/libs/common/src/vault/services/collection.service.ts @@ -188,7 +188,7 @@ export class CollectionService implements CollectionServiceAbstraction { await this.encryptedCollectionDataState.update(() => collections); } - async clear(userId?: UserId): Promise { + async clear(userId?: UserId): Promise { if (userId == null) { await this.encryptedCollectionDataState.update(() => null); await this.decryptedCollectionDataState.forceValue(null);