From c6e4a9ba754d0f992129f4d249161b0f6757d3eb Mon Sep 17 00:00:00 2001 From: SmithThe4th Date: Fri, 13 Jun 2025 10:58:38 -0400 Subject: [PATCH] Fix mapping issue between client and SDK (#15056) --- .../src/vault/models/domain/cipher.spec.ts | 5 ++++- libs/common/src/vault/models/domain/cipher.ts | 19 +++++++++++++------ libs/common/src/vault/models/domain/login.ts | 2 +- .../src/vault/models/view/cipher.view.ts | 2 ++ .../src/vault/services/cipher.service.ts | 1 + 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libs/common/src/vault/models/domain/cipher.spec.ts b/libs/common/src/vault/models/domain/cipher.spec.ts index 5c98ceda9f7..1b97ad06bc3 100644 --- a/libs/common/src/vault/models/domain/cipher.spec.ts +++ b/libs/common/src/vault/models/domain/cipher.spec.ts @@ -887,7 +887,10 @@ describe("Cipher DTO", () => { reprompt: SdkCipherRepromptType.None, organizationUseTotp: true, edit: true, - permissions: new CipherPermissionsApi(), + permissions: { + delete: false, + restore: false, + }, viewPassword: true, localData: { lastUsedDate: "2025-04-15T12:00:00.000Z", diff --git a/libs/common/src/vault/models/domain/cipher.ts b/libs/common/src/vault/models/domain/cipher.ts index f647adf198e..d816ebb24ce 100644 --- a/libs/common/src/vault/models/domain/cipher.ts +++ b/libs/common/src/vault/models/domain/cipher.ts @@ -292,6 +292,7 @@ export class Cipher extends Domain implements Decryptable { const domain = new Cipher(); const name = EncString.fromJSON(obj.name); const notes = EncString.fromJSON(obj.notes); + const creationDate = obj.creationDate == null ? null : new Date(obj.creationDate); const revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate); const deletedDate = obj.deletedDate == null ? null : new Date(obj.deletedDate); const attachments = obj.attachments?.map((a: any) => Attachment.fromJSON(a)); @@ -302,6 +303,7 @@ export class Cipher extends Domain implements Decryptable { Object.assign(domain, obj, { name, notes, + creationDate, revisionDate, deletedDate, attachments, @@ -341,17 +343,22 @@ export class Cipher extends Domain implements Decryptable { toSdkCipher(): SdkCipher { const sdkCipher: SdkCipher = { id: this.id, - organizationId: this.organizationId, - folderId: this.folderId, - collectionIds: this.collectionIds || [], + organizationId: this.organizationId ?? undefined, + folderId: this.folderId ?? undefined, + collectionIds: this.collectionIds ?? [], key: this.key?.toJSON(), name: this.name.toJSON(), notes: this.notes?.toJSON(), type: this.type, - favorite: this.favorite, - organizationUseTotp: this.organizationUseTotp, + favorite: this.favorite ?? false, + organizationUseTotp: this.organizationUseTotp ?? false, edit: this.edit, - permissions: this.permissions, + permissions: this.permissions + ? { + delete: this.permissions.delete, + restore: this.permissions.restore, + } + : undefined, viewPassword: this.viewPassword, localData: this.localData ? { diff --git a/libs/common/src/vault/models/domain/login.ts b/libs/common/src/vault/models/domain/login.ts index 1893212bdaa..b54251ca727 100644 --- a/libs/common/src/vault/models/domain/login.ts +++ b/libs/common/src/vault/models/domain/login.ts @@ -159,7 +159,7 @@ export class Login extends Domain { password: this.password?.toJSON(), passwordRevisionDate: this.passwordRevisionDate?.toISOString(), totp: this.totp?.toJSON(), - autofillOnPageLoad: this.autofillOnPageLoad, + autofillOnPageLoad: this.autofillOnPageLoad ?? undefined, fido2Credentials: this.fido2Credentials?.map((f) => f.toSdkFido2Credential()), }; } diff --git a/libs/common/src/vault/models/view/cipher.view.ts b/libs/common/src/vault/models/view/cipher.view.ts index e182025a332..353fffa8eef 100644 --- a/libs/common/src/vault/models/view/cipher.view.ts +++ b/libs/common/src/vault/models/view/cipher.view.ts @@ -188,6 +188,7 @@ export class CipherView implements View, InitializerMetadata { } const view = new CipherView(); + const creationDate = obj.creationDate == null ? null : new Date(obj.creationDate); const revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate); const deletedDate = obj.deletedDate == null ? null : new Date(obj.deletedDate); const attachments = obj.attachments?.map((a: any) => AttachmentView.fromJSON(a)); @@ -195,6 +196,7 @@ export class CipherView implements View, InitializerMetadata { const passwordHistory = obj.passwordHistory?.map((ph: any) => PasswordHistoryView.fromJSON(ph)); Object.assign(view, obj, { + creationDate: creationDate, revisionDate: revisionDate, deletedDate: deletedDate, attachments: attachments, diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 798821f0567..d8d180a7c3e 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -217,6 +217,7 @@ export class CipherService implements CipherServiceAbstraction { cipher.organizationId = model.organizationId; cipher.type = model.type; cipher.collectionIds = model.collectionIds; + cipher.creationDate = model.creationDate; cipher.revisionDate = model.revisionDate; cipher.reprompt = model.reprompt; cipher.edit = model.edit;