1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-18 18:33:50 +00:00

migrate cipher export and sub-models

This commit is contained in:
jaasen-livefront
2026-02-17 17:43:27 -08:00
parent ff775c7bbc
commit e5f261faf2
13 changed files with 201 additions and 219 deletions

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { Card as CardDomain } from "../../vault/models/domain/card";
import { CardView } from "../../vault/models/view/card.view";
@@ -29,21 +27,22 @@ export class CardExport {
}
static toDomain(req: CardExport, domain = new CardDomain()) {
domain.cardholderName = req.cardholderName != null ? new EncString(req.cardholderName) : null;
domain.brand = req.brand != null ? new EncString(req.brand) : null;
domain.number = req.number != null ? new EncString(req.number) : null;
domain.expMonth = req.expMonth != null ? new EncString(req.expMonth) : null;
domain.expYear = req.expYear != null ? new EncString(req.expYear) : null;
domain.code = req.code != null ? new EncString(req.code) : null;
domain.cardholderName =
req.cardholderName != null ? new EncString(req.cardholderName) : undefined;
domain.brand = req.brand != null ? new EncString(req.brand) : undefined;
domain.number = req.number != null ? new EncString(req.number) : undefined;
domain.expMonth = req.expMonth != null ? new EncString(req.expMonth) : undefined;
domain.expYear = req.expYear != null ? new EncString(req.expYear) : undefined;
domain.code = req.code != null ? new EncString(req.code) : undefined;
return domain;
}
cardholderName: string;
brand: string;
number: string;
expMonth: string;
expYear: string;
code: string;
cardholderName?: string;
brand?: string;
number?: string;
expMonth?: string;
expYear?: string;
code?: string;
constructor(o?: CardView | CardDomain) {
if (o == null) {

View File

@@ -1,13 +1,11 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Cipher as CipherDomain } from "../../vault/models/domain/cipher";
import { CipherView } from "../../vault/models/view/cipher.view";
import { CipherExport } from "./cipher.export";
export class CipherWithIdExport extends CipherExport {
id: string;
collectionIds: string[];
id: string = "";
collectionIds: string[] = [];
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CipherView | CipherDomain) {

View File

@@ -7,27 +7,24 @@ import { SshKeyExport } from "./ssh-key.export";
describe("Cipher Export", () => {
describe("toView", () => {
it.each([[null], [undefined]])(
"should preserve existing date values when request dates are nullish (=%p)",
(nullishDate) => {
const existingView = new CipherView();
existingView.creationDate = new Date("2023-01-01T00:00:00Z");
existingView.revisionDate = new Date("2023-01-02T00:00:00Z");
existingView.deletedDate = new Date("2023-01-03T00:00:00Z");
it("should preserve existing date values when request dates are undefined", () => {
const existingView = new CipherView();
existingView.creationDate = new Date("2023-01-01T00:00:00Z");
existingView.revisionDate = new Date("2023-01-02T00:00:00Z");
existingView.deletedDate = new Date("2023-01-03T00:00:00Z");
const request = CipherExport.template();
request.type = CipherType.SecureNote;
request.secureNote = SecureNoteExport.template();
request.creationDate = nullishDate as any;
request.revisionDate = nullishDate as any;
request.deletedDate = nullishDate as any;
const request = CipherExport.template();
request.type = CipherType.SecureNote;
request.secureNote = SecureNoteExport.template();
request.creationDate = undefined;
request.revisionDate = undefined;
request.deletedDate = undefined;
const resultView = CipherExport.toView(request, existingView);
expect(resultView.creationDate).toEqual(existingView.creationDate);
expect(resultView.revisionDate).toEqual(existingView.revisionDate);
expect(resultView.deletedDate).toEqual(existingView.deletedDate);
},
);
const resultView = CipherExport.toView(request, existingView);
expect(resultView.creationDate).toEqual(existingView.creationDate);
expect(resultView.revisionDate).toEqual(existingView.revisionDate);
expect(resultView.deletedDate).toEqual(existingView.deletedDate);
});
it("should set date values when request dates are provided", () => {
const request = CipherExport.template();

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { CipherRepromptType } from "../../vault/enums/cipher-reprompt-type";
import { CipherType } from "../../vault/enums/cipher-type";
@@ -18,25 +16,13 @@ import { safeGetString } from "./utils";
export class CipherExport {
static template(): CipherExport {
const req = new CipherExport();
req.organizationId = null;
req.collectionIds = null;
req.folderId = null;
req.type = CipherType.Login;
req.name = "Item name";
req.notes = "Some notes about this item.";
req.favorite = false;
req.fields = [];
req.login = null;
req.secureNote = null;
req.card = null;
req.identity = null;
req.sshKey = null;
req.reprompt = CipherRepromptType.None;
req.passwordHistory = [];
req.creationDate = null;
req.revisionDate = null;
req.deletedDate = null;
req.archivedDate = null;
return req;
}
@@ -54,7 +40,7 @@ export class CipherExport {
view.notes = req.notes;
view.favorite = req.favorite;
view.reprompt = req.reprompt ?? CipherRepromptType.None;
view.key = req.key != null ? new EncString(req.key) : null;
view.key = req.key != null ? new EncString(req.key) : undefined;
if (req.fields != null) {
view.fields = req.fields.map((f) => FieldExport.toView(f));
@@ -62,19 +48,30 @@ export class CipherExport {
switch (req.type) {
case CipherType.Login:
view.login = LoginExport.toView(req.login);
if (req.login != null) {
view.login = LoginExport.toView(req.login);
}
break;
case CipherType.SecureNote:
view.secureNote = SecureNoteExport.toView(req.secureNote);
if (req.secureNote != null) {
view.secureNote = SecureNoteExport.toView(req.secureNote);
}
break;
case CipherType.Card:
view.card = CardExport.toView(req.card);
if (req.card != null) {
view.card = CardExport.toView(req.card);
}
break;
case CipherType.Identity:
view.identity = IdentityExport.toView(req.identity);
if (req.identity != null) {
view.identity = IdentityExport.toView(req.identity);
}
break;
case CipherType.SshKey:
view.sshKey = SshKeyExport.toView(req.sshKey);
if (req.sshKey != null) {
// toView only returns undefined when req is null, which we've already checked
view.sshKey = SshKeyExport.toView(req.sshKey)!;
}
break;
}
@@ -95,11 +92,11 @@ export class CipherExport {
if (domain.organizationId == null) {
domain.organizationId = req.organizationId;
}
domain.name = req.name != null ? new EncString(req.name) : null;
domain.notes = req.notes != null ? new EncString(req.notes) : null;
domain.name = req.name != null ? new EncString(req.name) : new EncString("");
domain.notes = req.notes != null ? new EncString(req.notes) : undefined;
domain.favorite = req.favorite;
domain.reprompt = req.reprompt ?? CipherRepromptType.None;
domain.key = req.key != null ? new EncString(req.key) : null;
domain.key = req.key != null ? new EncString(req.key) : undefined;
if (req.fields != null) {
domain.fields = req.fields.map((f) => FieldExport.toDomain(f));
@@ -107,19 +104,29 @@ export class CipherExport {
switch (req.type) {
case CipherType.Login:
domain.login = LoginExport.toDomain(req.login);
if (req.login != null) {
domain.login = LoginExport.toDomain(req.login);
}
break;
case CipherType.SecureNote:
domain.secureNote = SecureNoteExport.toDomain(req.secureNote);
if (req.secureNote != null) {
domain.secureNote = SecureNoteExport.toDomain(req.secureNote);
}
break;
case CipherType.Card:
domain.card = CardExport.toDomain(req.card);
if (req.card != null) {
domain.card = CardExport.toDomain(req.card);
}
break;
case CipherType.Identity:
domain.identity = IdentityExport.toDomain(req.identity);
if (req.identity != null) {
domain.identity = IdentityExport.toDomain(req.identity);
}
break;
case CipherType.SshKey:
domain.sshKey = SshKeyExport.toDomain(req.sshKey);
if (req.sshKey != null) {
domain.sshKey = SshKeyExport.toDomain(req.sshKey);
}
break;
}
@@ -127,33 +134,33 @@ export class CipherExport {
domain.passwordHistory = req.passwordHistory.map((ph) => PasswordHistoryExport.toDomain(ph));
}
domain.creationDate = req.creationDate ? new Date(req.creationDate) : null;
domain.revisionDate = req.revisionDate ? new Date(req.revisionDate) : null;
domain.deletedDate = req.deletedDate ? new Date(req.deletedDate) : null;
domain.archivedDate = req.archivedDate ? new Date(req.archivedDate) : null;
domain.creationDate = req.creationDate ? new Date(req.creationDate) : domain.creationDate;
domain.revisionDate = req.revisionDate ? new Date(req.revisionDate) : domain.revisionDate;
domain.deletedDate = req.deletedDate ? new Date(req.deletedDate) : undefined;
domain.archivedDate = req.archivedDate ? new Date(req.archivedDate) : undefined;
return domain;
}
type: CipherType;
folderId: string;
organizationId: string;
collectionIds: string[];
name: string;
notes: string;
favorite: boolean;
fields: FieldExport[];
login: LoginExport;
secureNote: SecureNoteExport;
card: CardExport;
identity: IdentityExport;
sshKey: SshKeyExport;
reprompt: CipherRepromptType;
passwordHistory: PasswordHistoryExport[] = null;
revisionDate: Date = null;
creationDate: Date = null;
deletedDate: Date = null;
archivedDate: Date = null;
key: string;
type: CipherType = CipherType.Login;
folderId?: string;
organizationId?: string;
collectionIds?: string[];
name: string = "";
notes?: string;
favorite: boolean = false;
fields?: FieldExport[];
login?: LoginExport;
secureNote?: SecureNoteExport;
card?: CardExport;
identity?: IdentityExport;
sshKey?: SshKeyExport;
reprompt: CipherRepromptType = CipherRepromptType.None;
passwordHistory?: PasswordHistoryExport[];
revisionDate?: Date;
creationDate?: 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
build(o: CipherView | CipherDomain) {
@@ -162,7 +169,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;

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { Fido2Credential } from "../../vault/models/domain/fido2-credential";
import { Fido2CredentialView } from "../../vault/models/view/fido2-credential.view";
@@ -28,7 +26,7 @@ export class Fido2CredentialExport {
req.rpName = "rpName";
req.userDisplayName = "userDisplayName";
req.discoverable = "false";
req.creationDate = null;
req.creationDate = new Date();
return req;
}
@@ -62,36 +60,36 @@ export class Fido2CredentialExport {
* @returns Fido2Credential - The populated domain, or a new instance if none was provided.
*/
static toDomain(req: Fido2CredentialExport, domain = new Fido2Credential()) {
domain.credentialId = req.credentialId != null ? new EncString(req.credentialId) : null;
domain.keyType = req.keyType != null ? new EncString(req.keyType) : null;
domain.keyAlgorithm = req.keyAlgorithm != null ? new EncString(req.keyAlgorithm) : null;
domain.keyCurve = req.keyCurve != null ? new EncString(req.keyCurve) : null;
domain.keyValue = req.keyValue != null ? new EncString(req.keyValue) : null;
domain.rpId = req.rpId != null ? new EncString(req.rpId) : null;
domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : null;
domain.userName = req.userName != null ? new EncString(req.userName) : null;
domain.counter = req.counter != null ? new EncString(req.counter) : null;
domain.rpName = req.rpName != null ? new EncString(req.rpName) : null;
domain.credentialId = new EncString(req.credentialId);
domain.keyType = new EncString(req.keyType);
domain.keyAlgorithm = new EncString(req.keyAlgorithm);
domain.keyCurve = new EncString(req.keyCurve);
domain.keyValue = new EncString(req.keyValue);
domain.rpId = new EncString(req.rpId);
domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : undefined;
domain.userName = req.userName != null ? new EncString(req.userName) : undefined;
domain.counter = new EncString(req.counter);
domain.rpName = req.rpName != null ? new EncString(req.rpName) : undefined;
domain.userDisplayName =
req.userDisplayName != null ? new EncString(req.userDisplayName) : null;
domain.discoverable = req.discoverable != null ? new EncString(req.discoverable) : null;
domain.creationDate = req.creationDate != null ? new Date(req.creationDate) : null;
req.userDisplayName != null ? new EncString(req.userDisplayName) : undefined;
domain.discoverable = new EncString(req.discoverable);
domain.creationDate = new Date(req.creationDate);
return domain;
}
credentialId: string;
keyType: string;
keyAlgorithm: string;
keyCurve: string;
keyValue: string;
rpId: string;
userHandle: string;
userName: string;
counter: string;
rpName: string;
userDisplayName: string;
discoverable: string;
creationDate: Date;
credentialId: string = "";
keyType: string = "";
keyAlgorithm: string = "";
keyCurve: string = "";
keyValue: string = "";
rpId: string = "";
userHandle?: string;
userName?: string;
counter: string = "";
rpName?: string;
userDisplayName?: string;
discoverable: string = "false";
creationDate: Date = new Date();
/**
* Constructs a new Fid2CredentialExport instance.
@@ -103,20 +101,21 @@ 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(o instanceof Fido2CredentialView ? String(o.counter) : o.counter);
this.counter =
safeGetString(o instanceof Fido2CredentialView ? String(o.counter) : o.counter) ?? "";
this.rpName = safeGetString(o.rpName);
this.userDisplayName = safeGetString(o.userDisplayName);
this.discoverable = safeGetString(
o instanceof Fido2CredentialView ? String(o.discoverable) : o.discoverable,
);
this.discoverable =
safeGetString(o instanceof Fido2CredentialView ? String(o.discoverable) : o.discoverable) ??
"false";
this.creationDate = o.creationDate;
}
}

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { FieldType, LinkedIdType } from "../../vault/enums";
import { Field as FieldDomain } from "../../vault/models/domain/field";
@@ -26,16 +24,16 @@ export class FieldExport {
static toDomain(req: FieldExport, domain = new FieldDomain()) {
domain.type = req.type;
domain.value = req.value != null ? new EncString(req.value) : null;
domain.name = req.name != null ? new EncString(req.name) : null;
domain.value = req.value != null ? new EncString(req.value) : undefined;
domain.name = req.name != null ? new EncString(req.name) : undefined;
domain.linkedId = req.linkedId;
return domain;
}
name: string;
value: string;
type: FieldType;
linkedId: LinkedIdType;
name?: string;
value?: string;
type: FieldType = FieldType.Text;
linkedId?: LinkedIdType;
constructor(o?: FieldView | FieldDomain) {
if (o == null) {

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { Identity as IdentityDomain } from "../../vault/models/domain/identity";
import { IdentityView } from "../../vault/models/view/identity.view";
@@ -15,7 +13,6 @@ export class IdentityExport {
req.lastName = "Doe";
req.address1 = "123 Any St";
req.address2 = "Apt #123";
req.address3 = null;
req.city = "New York";
req.state = "NY";
req.postalCode = "10001";
@@ -53,45 +50,46 @@ export class IdentityExport {
}
static toDomain(req: IdentityExport, domain = new IdentityDomain()) {
domain.title = req.title != null ? new EncString(req.title) : null;
domain.firstName = req.firstName != null ? new EncString(req.firstName) : null;
domain.middleName = req.middleName != null ? new EncString(req.middleName) : null;
domain.lastName = req.lastName != null ? new EncString(req.lastName) : null;
domain.address1 = req.address1 != null ? new EncString(req.address1) : null;
domain.address2 = req.address2 != null ? new EncString(req.address2) : null;
domain.address3 = req.address3 != null ? new EncString(req.address3) : null;
domain.city = req.city != null ? new EncString(req.city) : null;
domain.state = req.state != null ? new EncString(req.state) : null;
domain.postalCode = req.postalCode != null ? new EncString(req.postalCode) : null;
domain.country = req.country != null ? new EncString(req.country) : null;
domain.company = req.company != null ? new EncString(req.company) : null;
domain.email = req.email != null ? new EncString(req.email) : null;
domain.phone = req.phone != null ? new EncString(req.phone) : null;
domain.ssn = req.ssn != null ? new EncString(req.ssn) : null;
domain.username = req.username != null ? new EncString(req.username) : null;
domain.passportNumber = req.passportNumber != null ? new EncString(req.passportNumber) : null;
domain.licenseNumber = req.licenseNumber != null ? new EncString(req.licenseNumber) : null;
domain.title = req.title != null ? new EncString(req.title) : undefined;
domain.firstName = req.firstName != null ? new EncString(req.firstName) : undefined;
domain.middleName = req.middleName != null ? new EncString(req.middleName) : undefined;
domain.lastName = req.lastName != null ? new EncString(req.lastName) : undefined;
domain.address1 = req.address1 != null ? new EncString(req.address1) : undefined;
domain.address2 = req.address2 != null ? new EncString(req.address2) : undefined;
domain.address3 = req.address3 != null ? new EncString(req.address3) : undefined;
domain.city = req.city != null ? new EncString(req.city) : undefined;
domain.state = req.state != null ? new EncString(req.state) : undefined;
domain.postalCode = req.postalCode != null ? new EncString(req.postalCode) : undefined;
domain.country = req.country != null ? new EncString(req.country) : undefined;
domain.company = req.company != null ? new EncString(req.company) : undefined;
domain.email = req.email != null ? new EncString(req.email) : undefined;
domain.phone = req.phone != null ? new EncString(req.phone) : undefined;
domain.ssn = req.ssn != null ? new EncString(req.ssn) : undefined;
domain.username = req.username != null ? new EncString(req.username) : undefined;
domain.passportNumber =
req.passportNumber != null ? new EncString(req.passportNumber) : undefined;
domain.licenseNumber = req.licenseNumber != null ? new EncString(req.licenseNumber) : undefined;
return domain;
}
title: string;
firstName: string;
middleName: string;
lastName: string;
address1: string;
address2: string;
address3: string;
city: string;
state: string;
postalCode: string;
country: string;
company: string;
email: string;
phone: string;
ssn: string;
username: string;
passportNumber: string;
licenseNumber: string;
title?: string;
firstName?: string;
middleName?: string;
lastName?: string;
address1?: string;
address2?: string;
address3?: string;
city?: string;
state?: string;
postalCode?: string;
country?: string;
company?: string;
email?: string;
phone?: string;
ssn?: string;
username?: string;
passportNumber?: string;
licenseNumber?: string;
constructor(o?: IdentityView | IdentityDomain) {
if (o == null) {

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { UriMatchStrategySetting } from "../../models/domain/domain-service";
import { LoginUri as LoginUriDomain } from "../../vault/models/domain/login-uri";
@@ -11,7 +9,6 @@ export class LoginUriExport {
static template(): LoginUriExport {
const req = new LoginUriExport();
req.uri = "https://google.com";
req.match = null;
return req;
}
@@ -22,15 +19,15 @@ export class LoginUriExport {
}
static toDomain(req: LoginUriExport, domain = new LoginUriDomain()) {
domain.uri = req.uri != null ? new EncString(req.uri) : null;
domain.uriChecksum = req.uriChecksum != null ? new EncString(req.uriChecksum) : null;
domain.uri = req.uri != null ? new EncString(req.uri) : undefined;
domain.uriChecksum = req.uriChecksum != null ? new EncString(req.uriChecksum) : undefined;
domain.match = req.match;
return domain;
}
uri: string;
uriChecksum: string | undefined;
match: UriMatchStrategySetting = null;
uri?: string;
uriChecksum?: string;
match?: UriMatchStrategySetting;
constructor(o?: LoginUriView | LoginUriDomain) {
if (o == null) {

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { Login as LoginDomain } from "../../vault/models/domain/login";
import { LoginView } from "../../vault/models/view/login.view";
@@ -36,9 +34,9 @@ export class LoginExport {
if (req.uris != null) {
domain.uris = req.uris.map((u) => LoginUriExport.toDomain(u));
}
domain.username = req.username != null ? new EncString(req.username) : null;
domain.password = req.password != null ? new EncString(req.password) : null;
domain.totp = req.totp != null ? new EncString(req.totp) : null;
domain.username = req.username != null ? new EncString(req.username) : undefined;
domain.password = req.password != null ? new EncString(req.password) : undefined;
domain.totp = req.totp != null ? new EncString(req.totp) : undefined;
if (req.fido2Credentials != null) {
domain.fido2Credentials = req.fido2Credentials.map((f2) =>
Fido2CredentialExport.toDomain(f2),
@@ -48,11 +46,11 @@ export class LoginExport {
return domain;
}
uris: LoginUriExport[];
username: string;
password: string;
totp: string;
fido2Credentials: Fido2CredentialExport[];
uris?: LoginUriExport[];
username?: string;
password?: string;
totp?: string;
fido2Credentials?: Fido2CredentialExport[];
constructor(o?: LoginView | LoginDomain) {
if (o == null) {

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { Password } from "../../vault/models/domain/password";
import { PasswordHistoryView } from "../../vault/models/view/password-history.view";
@@ -9,32 +7,30 @@ import { safeGetString } from "./utils";
export class PasswordHistoryExport {
static template(): PasswordHistoryExport {
const req = new PasswordHistoryExport();
req.password = null;
req.lastUsedDate = null;
return req;
}
static toView(req: PasswordHistoryExport, view = new PasswordHistoryView()) {
view.password = req.password;
view.lastUsedDate = req.lastUsedDate ? new Date(req.lastUsedDate) : null;
view.lastUsedDate = req.lastUsedDate ? new Date(req.lastUsedDate) : new Date();
return view;
}
static toDomain(req: PasswordHistoryExport, domain = new Password()) {
domain.password = req.password != null ? new EncString(req.password) : null;
domain.lastUsedDate = req.lastUsedDate ? new Date(req.lastUsedDate) : null;
domain.password = new EncString(req.password);
domain.lastUsedDate = req.lastUsedDate ? new Date(req.lastUsedDate) : new Date();
return domain;
}
password: string;
lastUsedDate: Date = null;
password: string = "";
lastUsedDate?: Date;
constructor(o?: PasswordHistoryView | Password) {
if (o == null) {
return;
}
this.password = safeGetString(o.password);
this.lastUsedDate = o.lastUsedDate;
this.password = safeGetString(o.password) ?? "";
this.lastUsedDate = o.lastUsedDate ?? undefined;
}
}

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { SecureNoteType } from "../../vault/enums";
import { SecureNote as SecureNoteDomain } from "../../vault/models/domain/secure-note";
import { SecureNoteView } from "../../vault/models/view/secure-note.view";
@@ -21,7 +19,7 @@ export class SecureNoteExport {
return view;
}
type: SecureNoteType;
type: SecureNoteType = SecureNoteType.Generic;
constructor(o?: SecureNoteView | SecureNoteDomain) {
if (o == null) {

View File

@@ -1,6 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { EncString } from "../../key-management/crypto/models/enc-string";
import { SshKey as SshKeyDomain } from "../../vault/models/domain/ssh-key";
import { SshKeyView as SshKeyView } from "../../vault/models/view/ssh-key.view";
@@ -45,17 +42,17 @@ export class SshKeyExport {
return domain;
}
privateKey: string;
publicKey: string;
keyFingerprint: string;
privateKey: string = "";
publicKey: string = "";
keyFingerprint: string = "";
constructor(o?: SshKeyView | SshKeyDomain) {
if (o == null) {
return;
}
this.privateKey = safeGetString(o.privateKey);
this.publicKey = safeGetString(o.publicKey);
this.keyFingerprint = safeGetString(o.keyFingerprint);
this.privateKey = safeGetString(o.privateKey) ?? "";
this.publicKey = safeGetString(o.publicKey) ?? "";
this.keyFingerprint = safeGetString(o.keyFingerprint) ?? "";
}
}

View File

@@ -1,8 +1,8 @@
import { EncString } from "../../key-management/crypto/models/enc-string";
export function safeGetString(value: string | EncString) {
export function safeGetString(value: string | EncString | undefined | null): string | undefined {
if (value == null) {
return null;
return undefined;
}
if (typeof value == "string") {