diff --git a/libs/common/src/vault/models/view/cipher.view.ts b/libs/common/src/vault/models/view/cipher.view.ts index d047ab788f9..edd7eb5b72b 100644 --- a/libs/common/src/vault/models/view/cipher.view.ts +++ b/libs/common/src/vault/models/view/cipher.view.ts @@ -282,7 +282,21 @@ export class CipherView implements View, InitializerMetadata { cipherView.folderId = uuidAsString(obj.folderId); cipherView.name = obj.name; cipherView.notes = obj.notes; - cipherView.type = obj.type; + + // SDK returns type as a discriminated union object, extract the actual CipherType + const sdkType = (obj.type as any) ?? { login: {} }; + if ("login" in sdkType) { + cipherView.type = CipherType.Login; + } else if ("card" in sdkType) { + cipherView.type = CipherType.Card; + } else if ("identity" in sdkType) { + cipherView.type = CipherType.Identity; + } else if ("secureNote" in sdkType) { + cipherView.type = CipherType.SecureNote; + } else if ("sshKey" in sdkType) { + cipherView.type = CipherType.SshKey; + } + cipherView.favorite = obj.favorite; cipherView.organizationUseTotp = obj.organizationUseTotp; cipherView.permissions = obj.permissions @@ -291,12 +305,21 @@ export class CipherView implements View, InitializerMetadata { cipherView.edit = obj.edit; cipherView.viewPassword = obj.viewPassword; cipherView.localData = fromSdkLocalData(obj.localData); + // Convert iterables to arrays to ensure .map() works cipherView.attachments = - obj.attachments?.map((a) => AttachmentView.fromSdkAttachmentView(a)!) ?? []; - cipherView.fields = obj.fields?.map((f) => FieldView.fromSdkFieldView(f)!) ?? []; + obj.attachments != null + ? Array.from(obj.attachments).map((a) => AttachmentView.fromSdkAttachmentView(a)!) + : []; + cipherView.fields = + obj.fields != null ? Array.from(obj.fields).map((f) => FieldView.fromSdkFieldView(f)!) : []; cipherView.passwordHistory = - obj.passwordHistory?.map((ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)!) ?? []; - cipherView.collectionIds = obj.collectionIds?.map((i) => uuidAsString(i)) ?? []; + obj.passwordHistory != null + ? 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.creationDate = new Date(obj.creationDate); cipherView.deletedDate = obj.deletedDate == null ? undefined : new Date(obj.deletedDate); diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index f2eecf08fdc..cc433317839 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -509,10 +509,21 @@ export class CipherService implements CipherServiceAbstraction { const decryptResult = await ref.value.vault().ciphers().list(); - const successViews = decryptResult.successes.map((sdkCipherView: any) => + // Convert successes - SDK returns array of SdkCipherView + const successArray = Array.isArray(decryptResult.successes) + ? decryptResult.successes + : Array.from(decryptResult.successes ?? []); + + const successViews = successArray.map((sdkCipherView: any) => CipherView.fromSdkCipherView(sdkCipherView), ); - const failureViews: CipherView[] = decryptResult.failures.map((failure) => { + + // Convert failures to CipherView with error markers + const failureArray = Array.isArray(decryptResult.failures) + ? decryptResult.failures + : Array.from(decryptResult.failures ?? []); + + const failureViews: CipherView[] = failureArray.map((failure: any) => { const cipher = Cipher.fromSdkCipher(failure); const cipherView = new CipherView(cipher); cipherView.name = DECRYPT_ERROR; @@ -805,7 +816,6 @@ export class CipherService implements CipherServiceAbstraction { .admin() .list_org_ciphers(asUuid(organizationId), includeMemberItems); - // Convert successful decryptions to CipherView[] const cipherViews = decryptResult.successes.map((sdkCipherView: any) => CipherView.fromSdkCipherView(sdkCipherView), ); diff --git a/libs/common/src/vault/utils/cipher-view-like-utils.ts b/libs/common/src/vault/utils/cipher-view-like-utils.ts index 04adb8d4832..d7633d82bee 100644 --- a/libs/common/src/vault/utils/cipher-view-like-utils.ts +++ b/libs/common/src/vault/utils/cipher-view-like-utils.ts @@ -242,7 +242,7 @@ export class CipherViewLikeUtils { _copyField = "usernameIdentity"; } - return cipher.copyableFields.includes(copyActionToCopyableFieldMap[_copyField]); + return cipher.copyableFields?.includes(copyActionToCopyableFieldMap[_copyField]) ?? false; } // When the full cipher is available, check the specific field