From 3d2bcf8b80009691ec1b2332e01cc00f29f7031f Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Tue, 4 Nov 2025 16:40:04 -0800 Subject: [PATCH] clean up string values --- .../common/src/models/export/cipher.export.ts | 35 +++++++------------ .../src/models/export/collection.export.ts | 2 +- .../models/export/fido2-credential.export.ts | 16 ++++----- libs/common/src/models/export/utils.ts | 4 +-- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libs/common/src/models/export/cipher.export.ts b/libs/common/src/models/export/cipher.export.ts index d68fa0bd9d4..aa885e8a72b 100644 --- a/libs/common/src/models/export/cipher.export.ts +++ b/libs/common/src/models/export/cipher.export.ts @@ -14,13 +14,6 @@ import { SshKeyExport } from "./ssh-key.export"; import { safeGetString } from "./utils"; export class CipherExport { - constructor() { - this.archivedDate = new Date(); - this.creationDate = new Date(); - this.deletedDate = new Date(); - this.revisionDate = new Date(); - } - static template(): CipherExport { const req = new CipherExport(); req.organizationId = ""; @@ -33,10 +26,6 @@ export class CipherExport { req.fields = []; req.reprompt = CipherRepromptType.None; req.passwordHistory = []; - req.creationDate = new Date(); - req.revisionDate = new Date(); - req.deletedDate = new Date(); - req.archivedDate = new Date(); return req; } @@ -110,11 +99,11 @@ export class CipherExport { if (domain.organizationId == null) { domain.organizationId = req.organizationId; } - domain.name = new EncString(req.name ? req.name : ""); - domain.notes = new EncString(req.notes ? req.notes : ""); + domain.name = new EncString(req.name ?? ""); + domain.notes = new EncString(req.notes ?? ""); domain.favorite = req.favorite; domain.reprompt = req.reprompt ?? CipherRepromptType.None; - domain.key = new EncString(req.key ? req.key : ""); + domain.key = new EncString(req.key ?? ""); if (req.fields != null) { domain.fields = req.fields.map((f) => FieldExport.toDomain(f)); @@ -159,8 +148,8 @@ export class CipherExport { domain.creationDate = req.creationDate ? new Date(req.creationDate) : new Date(); domain.revisionDate = req.revisionDate ? new Date(req.revisionDate) : new Date(); - domain.deletedDate = req.deletedDate ? new Date(req.deletedDate) : new Date(); - domain.archivedDate = req.archivedDate ? new Date(req.archivedDate) : new Date(); + domain.deletedDate = req.deletedDate ? new Date(req.deletedDate) : undefined; + domain.archivedDate = req.archivedDate ? new Date(req.archivedDate) : undefined; return domain; } @@ -179,10 +168,10 @@ export class CipherExport { sshKey?: SshKeyExport; reprompt: CipherRepromptType = CipherRepromptType.None; passwordHistory: PasswordHistoryExport[] = []; - revisionDate: Date; - creationDate: Date; - deletedDate: Date; - archivedDate: Date; + revisionDate: Date = new Date(); + creationDate: Date = new Date(); + deletedDate?: Date; + archivedDate?: Date; key?: string; // Use build method instead of ctor so that we can control order of JSON stringify for pretty print @@ -192,7 +181,7 @@ export class CipherExport { this.type = o.type; this.reprompt = o.reprompt; - this.name = safeGetString(o.name); + this.name = safeGetString(o.name) ?? ""; this.notes = safeGetString(o.notes); if ("key" in o) { this.key = o.key?.encryptedString ?? ""; @@ -228,7 +217,7 @@ export class CipherExport { this.creationDate = o.creationDate; this.revisionDate = o.revisionDate; - this.deletedDate = o.deletedDate ?? new Date(); - this.archivedDate = o.archivedDate ?? new Date(); + this.deletedDate = o.deletedDate; + this.archivedDate = o.archivedDate; } } diff --git a/libs/common/src/models/export/collection.export.ts b/libs/common/src/models/export/collection.export.ts index 981dafdfd1a..f21555c6b7a 100644 --- a/libs/common/src/models/export/collection.export.ts +++ b/libs/common/src/models/export/collection.export.ts @@ -48,7 +48,7 @@ export class CollectionExport { // Use build method instead of ctor so that we can control order of JSON stringify for pretty print build(o: CollectionView | CollectionDomain) { this.organizationId = o.organizationId; - this.name = safeGetString(o.name); + this.name = safeGetString(o.name) ?? ""; this.externalId = o.externalId; } } diff --git a/libs/common/src/models/export/fido2-credential.export.ts b/libs/common/src/models/export/fido2-credential.export.ts index ce8d6cc9ed0..402fa025599 100644 --- a/libs/common/src/models/export/fido2-credential.export.ts +++ b/libs/common/src/models/export/fido2-credential.export.ts @@ -100,18 +100,18 @@ export class Fido2CredentialExport { return; } - this.credentialId = safeGetString(o.credentialId); - this.keyType = safeGetString(o.keyType); - this.keyAlgorithm = safeGetString(o.keyAlgorithm); - this.keyCurve = safeGetString(o.keyCurve); - this.keyValue = safeGetString(o.keyValue); - this.rpId = safeGetString(o.rpId); + this.credentialId = safeGetString(o.credentialId) ?? ""; + this.keyType = safeGetString(o.keyType) ?? ""; + this.keyAlgorithm = safeGetString(o.keyAlgorithm) ?? ""; + this.keyCurve = safeGetString(o.keyCurve) ?? ""; + this.keyValue = safeGetString(o.keyValue) ?? ""; + this.rpId = safeGetString(o.rpId) ?? ""; this.userHandle = safeGetString(o.userHandle); this.userName = safeGetString(o.userName); - this.counter = safeGetString(String(o.counter)); + this.counter = safeGetString(String(o.counter)) ?? ""; this.rpName = safeGetString(o.rpName); this.userDisplayName = safeGetString(o.userDisplayName); - this.discoverable = safeGetString(String(o.discoverable)); + this.discoverable = safeGetString(String(o.discoverable)) ?? ""; this.creationDate = o.creationDate; } } diff --git a/libs/common/src/models/export/utils.ts b/libs/common/src/models/export/utils.ts index acd0a72849c..219eec2e475 100644 --- a/libs/common/src/models/export/utils.ts +++ b/libs/common/src/models/export/utils.ts @@ -2,11 +2,11 @@ import { EncString } from "../../key-management/crypto/models/enc-string"; export function safeGetString(value?: string | EncString) { if (!value) { - return ""; + return undefined; } if (typeof value == "string") { return value; } - return value?.encryptedString ?? ""; + return value?.encryptedString ?? undefined; }