1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-27 10:03:23 +00:00

Simplifications from PR feedback

This commit is contained in:
Nik Gilmore
2026-01-28 14:11:23 -08:00
parent f66d7f4566
commit e23af8b65e
3 changed files with 13 additions and 34 deletions

View File

@@ -316,20 +316,14 @@ export class CipherView implements View, InitializerMetadata {
cipherView.viewPassword = obj.viewPassword; cipherView.viewPassword = obj.viewPassword;
cipherView.localData = fromSdkLocalData(obj.localData); cipherView.localData = fromSdkLocalData(obj.localData);
// Convert iterables to arrays to ensure .map() works // Convert iterables to arrays to ensure .map() works
cipherView.attachments = cipherView.attachments = (obj.attachments ?? []).map(
obj.attachments != null (a) => AttachmentView.fromSdkAttachmentView(a)!,
? Array.from(obj.attachments).map((a) => AttachmentView.fromSdkAttachmentView(a)!) );
: []; cipherView.fields = (obj.fields ?? []).map((f) => FieldView.fromSdkFieldView(f)!);
cipherView.fields = cipherView.passwordHistory = (obj.passwordHistory ?? []).map(
obj.fields != null ? Array.from(obj.fields).map((f) => FieldView.fromSdkFieldView(f)!) : []; (ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)!,
cipherView.passwordHistory = );
obj.passwordHistory != null cipherView.collectionIds = (obj.collectionIds ?? []).map((i) => uuidAsString(i));
? Array.from(obj.passwordHistory).map(
(ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)!,
)
: [];
cipherView.collectionIds =
obj.collectionIds != null ? Array.from(obj.collectionIds).map((i) => uuidAsString(i)) : [];
cipherView.revisionDate = new Date(obj.revisionDate); cipherView.revisionDate = new Date(obj.revisionDate);
cipherView.creationDate = new Date(obj.creationDate); cipherView.creationDate = new Date(obj.creationDate);
cipherView.deletedDate = obj.deletedDate == null ? undefined : new Date(obj.deletedDate); cipherView.deletedDate = obj.deletedDate == null ? undefined : new Date(obj.deletedDate);

View File

@@ -274,23 +274,12 @@ export class DefaultCipherSdkService implements CipherSdkService {
const decryptResult = await ref.value.vault().ciphers().list(); const decryptResult = await ref.value.vault().ciphers().list();
// Convert successes - SDK returns array of SdkCipherView const successes = [...(decryptResult.successes ?? [])]
const successArray = Array.isArray(decryptResult.successes)
? decryptResult.successes
: Array.from(decryptResult.successes ?? []);
const successes = successArray
.map((sdkCipherView: any) => CipherView.fromSdkCipherView(sdkCipherView)) .map((sdkCipherView: any) => CipherView.fromSdkCipherView(sdkCipherView))
.filter((v): v is CipherView => v !== undefined); .filter((v): v is CipherView => v !== undefined);
// Convert failures to CipherView with error markers const failures: CipherView[] = [...(decryptResult.failures ?? [])].map((failure: any) => {
const failureArray = Array.isArray(decryptResult.failures) const cipherView = new CipherView(Cipher.fromSdkCipher(failure));
? decryptResult.failures
: Array.from(decryptResult.failures ?? []);
const failures: CipherView[] = failureArray.map((failure: any) => {
const cipher = Cipher.fromSdkCipher(failure);
const cipherView = new CipherView(cipher);
cipherView.name = DECRYPT_ERROR; cipherView.name = DECRYPT_ERROR;
cipherView.decryptionFailure = true; cipherView.decryptionFailure = true;
return cipherView; return cipherView;

View File

@@ -492,9 +492,7 @@ export class CipherService implements CipherServiceAbstraction {
* @deprecated Use `cipherViews$` observable instead * @deprecated Use `cipherViews$` observable instead
*/ */
async getAllDecrypted(userId: UserId): Promise<CipherView[]> { async getAllDecrypted(userId: UserId): Promise<CipherView[]> {
const useSdk = await this.configService.getFeatureFlag( const useSdk = await firstValueFrom(this.sdkCipherCrudEnabled$);
FeatureFlag.PM27632_SdkCipherCrudOperations,
);
if (useSdk) { if (useSdk) {
return this.getAllDecryptedUsingSdk(userId); return this.getAllDecryptedUsingSdk(userId);
} }
@@ -768,9 +766,7 @@ export class CipherService implements CipherServiceAbstraction {
organizationId: string, organizationId: string,
includeMemberItems?: boolean, includeMemberItems?: boolean,
): Promise<CipherView[]> { ): Promise<CipherView[]> {
const useSdk = await this.configService.getFeatureFlag( const useSdk = await firstValueFrom(this.sdkCipherCrudEnabled$);
FeatureFlag.PM27632_SdkCipherCrudOperations,
);
if (useSdk) { if (useSdk) {
return this.getAllFromApiForOrganizationUsingSdk(organizationId, includeMemberItems ?? false); return this.getAllFromApiForOrganizationUsingSdk(organizationId, includeMemberItems ?? false);
} }