1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +00:00

[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
This commit is contained in:
Jake Fink
2024-08-05 11:39:08 -04:00
committed by GitHub
parent 157f3a5d39
commit 2819ac597f
24 changed files with 110 additions and 81 deletions

View File

@@ -16,6 +16,8 @@ export class PolicyApiServiceAbstraction {
organizationUserId: string,
) => Promise<Policy[] | undefined>;
getMasterPasswordPolicyOptsForOrgUser: (orgId: string) => Promise<MasterPasswordPolicyOptions>;
getMasterPasswordPolicyOptsForOrgUser: (
orgId: string,
) => Promise<MasterPasswordPolicyOptions | null>;
putPolicy: (organizationId: string, type: PolicyType, request: PolicyRequest) => Promise<any>;
}

View File

@@ -64,8 +64,10 @@ function mapToSingleOrganization(organizationId: string) {
}
export class OrganizationService implements InternalOrganizationServiceAbstraction {
organizations$ = this.getOrganizationsFromState$();
memberOrganizations$ = this.organizations$.pipe(mapToExcludeProviderOrganizations());
organizations$: Observable<Organization[]> = this.getOrganizationsFromState$();
memberOrganizations$: Observable<Organization[]> = this.organizations$.pipe(
mapToExcludeProviderOrganizations(),
);
constructor(private stateProvider: StateProvider) {}

View File

@@ -32,7 +32,7 @@ export class PolicyService implements InternalPolicyServiceAbstraction {
private organizationService: OrganizationService,
) {}
get$(policyType: PolicyType) {
get$(policyType: PolicyType): Observable<Policy> {
const filteredPolicies$ = this.activeUserPolicies$.pipe(
map((policies) => policies.filter((p) => p.type === policyType)),
);

View File

@@ -72,7 +72,7 @@ export abstract class AccountService {
* Updates the `activeAccount$` observable with the new active account.
* @param userId
*/
abstract switchAccount(userId: UserId): Promise<void>;
abstract switchAccount(userId: UserId | null): Promise<void>;
/**
* Cleans personal information for the given account from the `accounts$` observable. Does not remove the userId from the observable.
*

View File

@@ -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<Record<UserId, AccountInfo>>;
private activeAccountIdState: GlobalState<UserId | undefined>;
accounts$;
activeAccount$;
accountActivity$;
sortedUserIds$;
nextUpAccount$;
accounts$: Observable<Record<UserId, AccountInfo>>;
activeAccount$: Observable<{ id: UserId | undefined } & AccountInfo>;
accountActivity$: Observable<Record<UserId, Date>>;
sortedUserIds$: Observable<UserId[]>;
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<void> {
async switchAccount(userId: UserId | null): Promise<void> {
let updateActivity = false;
await this.activeAccountIdState.update(
(_, accounts) => {

View File

@@ -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<Organization> {
const orgs = await this.organizationService.getAll();
return orgs.find(
(o) =>

View File

@@ -888,7 +888,7 @@ export class CryptoService implements CryptoServiceAbstraction {
return this.encryptService.decryptToBytes(encBuffer, key);
}
userKey$(userId: UserId) {
userKey$(userId: UserId): Observable<UserKey> {
return this.stateProvider.getUser(userId, USER_KEY).state$;
}
@@ -1013,7 +1013,7 @@ export class CryptoService implements CryptoServiceAbstraction {
);
}
orgKeys$(userId: UserId) {
orgKeys$(userId: UserId): Observable<Record<OrganizationId, OrgKey> | null> {
return this.cipherDecryptionKeys$(userId, true).pipe(map((keys) => keys?.orgKeys));
}

View File

@@ -269,7 +269,7 @@ export class DefaultEnvironmentService implements EnvironmentService {
}
}
async getEnvironment(userId?: UserId) {
async getEnvironment(userId?: UserId): Promise<Environment | undefined> {
if (userId == null) {
return await firstValueFrom(this.environment$);
}

View File

@@ -129,7 +129,7 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
*/
upsert: (cipher: CipherData | CipherData[]) => Promise<Record<CipherId, CipherData>>;
replace: (ciphers: { [id: string]: CipherData }) => Promise<any>;
clear: (userId: string) => Promise<any>;
clear: (userId?: string) => Promise<void>;
moveManyWithServer: (ids: string[], folderId: string) => Promise<any>;
delete: (id: string | string[]) => Promise<any>;
deleteWithServer: (id: string, asAdmin?: boolean) => Promise<any>;

View File

@@ -23,6 +23,6 @@ export abstract class CollectionService {
getNested: (id: string) => Promise<TreeNode<CollectionView>>;
upsert: (collection: CollectionData | CollectionData[]) => Promise<any>;
replace: (collections: { [id: string]: CollectionData }) => Promise<any>;
clear: (userId: string) => Promise<any>;
clear: (userId?: string) => Promise<void>;
delete: (id: string | string[]) => Promise<any>;
}

View File

@@ -17,7 +17,7 @@ export abstract class FolderService implements UserKeyRotationDataProvider<Folde
clearCache: () => Promise<void>;
encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise<Folder>;
get: (id: string) => Promise<Folder>;
getDecrypted$: (id: string) => Observable<FolderView>;
getDecrypted$: (id: string) => Observable<FolderView | undefined>;
getAllFromState: () => Promise<Folder[]>;
/**
* @deprecated Only use in CLI!
@@ -46,6 +46,6 @@ export abstract class FolderService implements UserKeyRotationDataProvider<Folde
export abstract class InternalFolderService extends FolderService {
upsert: (folder: FolderData | FolderData[]) => Promise<void>;
replace: (folders: { [id: string]: FolderData }) => Promise<void>;
clear: (userId: string) => Promise<any>;
clear: (userId?: string) => Promise<void>;
delete: (id: string | string[]) => Promise<any>;
}

View File

@@ -571,7 +571,7 @@ export class CipherService implements CipherServiceAbstraction {
return this.sortedCiphersCache.getNext(cacheKey);
}
async getNextIdentityCipher() {
async getNextIdentityCipher(): Promise<CipherView> {
const cacheKey = "identityCiphers";
if (!this.sortedCiphersCache.isCached(cacheKey)) {
@@ -926,7 +926,7 @@ export class CipherService implements CipherServiceAbstraction {
return updatedCiphers;
}
async clear(userId?: UserId): Promise<any> {
async clear(userId?: UserId): Promise<void> {
userId ??= await firstValueFrom(this.stateProvider.activeUserId$);
await this.clearEncryptedCiphersState(userId);
await this.clearCache(userId);

View File

@@ -188,7 +188,7 @@ export class CollectionService implements CollectionServiceAbstraction {
await this.encryptedCollectionDataState.update(() => collections);
}
async clear(userId?: UserId): Promise<any> {
async clear(userId?: UserId): Promise<void> {
if (userId == null) {
await this.encryptedCollectionDataState.update(() => null);
await this.decryptedCollectionDataState.forceValue(null);