diff --git a/libs/common/src/models/export/field.export.ts b/libs/common/src/models/export/field.export.ts index 6c2fbc73bb5..4d2e61b662e 100644 --- a/libs/common/src/models/export/field.export.ts +++ b/libs/common/src/models/export/field.export.ts @@ -24,24 +24,24 @@ 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 = new EncString(req.value ?? ""); + domain.name = new EncString(req.name ?? ""); 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) { return; } - this.name = safeGetString(o.name); - this.value = safeGetString(o.value); + this.name = safeGetString(o.name ?? "") ?? ""; + this.value = safeGetString(o.value ?? "") ?? ""; this.type = o.type; this.linkedId = o.linkedId; } diff --git a/libs/common/src/models/export/folder-with-id.export.ts b/libs/common/src/models/export/folder-with-id.export.ts index 31636cfcfe3..4c31ccba137 100644 --- a/libs/common/src/models/export/folder-with-id.export.ts +++ b/libs/common/src/models/export/folder-with-id.export.ts @@ -1,12 +1,10 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore import { Folder as FolderDomain } from "../../vault/models/domain/folder"; import { FolderView } from "../../vault/models/view/folder.view"; import { FolderExport } from "./folder.export"; export class FolderWithIdExport extends FolderExport { - id: string; + id: string = ""; static toView(req: FolderWithIdExport, view = new FolderView()) { view.id = req.id; diff --git a/libs/common/src/models/export/folder.export.ts b/libs/common/src/models/export/folder.export.ts index 96f0f1058b8..071c731bf2b 100644 --- a/libs/common/src/models/export/folder.export.ts +++ b/libs/common/src/models/export/folder.export.ts @@ -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 { Folder as FolderDomain } from "../../vault/models/domain/folder"; import { FolderView } from "../../vault/models/view/folder.view"; @@ -19,14 +17,14 @@ export class FolderExport { } static toDomain(req: FolderExport, domain = new FolderDomain()) { - domain.name = req.name != null ? new EncString(req.name) : null; + domain.name = new EncString(req.name ?? ""); return domain; } - name: string; + name: string = ""; // Use build method instead of ctor so that we can control order of JSON stringify for pretty print build(o: FolderView | FolderDomain) { - this.name = safeGetString(o.name); + this.name = safeGetString(o.name ?? "") ?? ""; } } diff --git a/libs/common/src/models/export/identity.export.ts b/libs/common/src/models/export/identity.export.ts index 275c6223f33..bcf3de38b44 100644 --- a/libs/common/src/models/export/identity.export.ts +++ b/libs/common/src/models/export/identity.export.ts @@ -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,7 @@ export class IdentityExport { req.lastName = "Doe"; req.address1 = "123 Any St"; req.address2 = "Apt #123"; - req.address3 = null; + req.address3 = ""; req.city = "New York"; req.state = "NY"; req.postalCode = "10001"; @@ -53,68 +51,68 @@ 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 = new EncString(req.title ?? ""); + domain.firstName = new EncString(req.firstName ?? ""); + domain.middleName = new EncString(req.middleName ?? ""); + domain.lastName = new EncString(req.lastName ?? ""); + domain.address1 = new EncString(req.address1 ?? ""); + domain.address2 = new EncString(req.address2 ?? ""); + domain.address3 = new EncString(req.address3 ?? ""); + domain.city = new EncString(req.city ?? ""); + domain.state = new EncString(req.state ?? ""); + domain.postalCode = new EncString(req.postalCode ?? ""); + domain.country = new EncString(req.country ?? ""); + domain.company = new EncString(req.company ?? ""); + domain.email = new EncString(req.email ?? ""); + domain.phone = new EncString(req.phone ?? ""); + domain.ssn = new EncString(req.ssn ?? ""); + domain.username = new EncString(req.username ?? ""); + domain.passportNumber = new EncString(req.passportNumber ?? ""); + domain.licenseNumber = new EncString(req.licenseNumber ?? ""); 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) { return; } - this.title = safeGetString(o.title); - this.firstName = safeGetString(o.firstName); - this.middleName = safeGetString(o.middleName); - this.lastName = safeGetString(o.lastName); - this.address1 = safeGetString(o.address1); - this.address2 = safeGetString(o.address2); - this.address3 = safeGetString(o.address3); - this.city = safeGetString(o.city); - this.state = safeGetString(o.state); - this.postalCode = safeGetString(o.postalCode); - this.country = safeGetString(o.country); - this.company = safeGetString(o.company); - this.email = safeGetString(o.email); - this.phone = safeGetString(o.phone); - this.ssn = safeGetString(o.ssn); - this.username = safeGetString(o.username); - this.passportNumber = safeGetString(o.passportNumber); - this.licenseNumber = safeGetString(o.licenseNumber); + this.title = safeGetString(o.title ?? "") ?? ""; + this.firstName = safeGetString(o.firstName ?? "") ?? ""; + this.middleName = safeGetString(o.middleName ?? "") ?? ""; + this.lastName = safeGetString(o.lastName ?? "") ?? ""; + this.address1 = safeGetString(o.address1 ?? "") ?? ""; + this.address2 = safeGetString(o.address2 ?? "") ?? ""; + this.address3 = safeGetString(o.address3 ?? "") ?? ""; + this.city = safeGetString(o.city ?? "") ?? ""; + this.state = safeGetString(o.state ?? "") ?? ""; + this.postalCode = safeGetString(o.postalCode ?? "") ?? ""; + this.country = safeGetString(o.country ?? "") ?? ""; + this.company = safeGetString(o.company ?? "") ?? ""; + this.email = safeGetString(o.email ?? "") ?? ""; + this.phone = safeGetString(o.phone ?? "") ?? ""; + this.ssn = safeGetString(o.ssn ?? "") ?? ""; + this.username = safeGetString(o.username ?? "") ?? ""; + this.passportNumber = safeGetString(o.passportNumber ?? "") ?? ""; + this.licenseNumber = safeGetString(o.licenseNumber ?? "") ?? ""; } } diff --git a/libs/common/src/models/export/login-uri.export.ts b/libs/common/src/models/export/login-uri.export.ts index 73dfeed5a80..d33682ab740 100644 --- a/libs/common/src/models/export/login-uri.export.ts +++ b/libs/common/src/models/export/login-uri.export.ts @@ -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,22 +19,22 @@ 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 = new EncString(req.uri ?? ""); + domain.uriChecksum = new EncString(req.uriChecksum ?? ""); domain.match = req.match; return domain; } - uri: string; + uri: string = ""; uriChecksum: string | undefined; - match: UriMatchStrategySetting = null; + match?: UriMatchStrategySetting; constructor(o?: LoginUriView | LoginUriDomain) { if (o == null) { return; } - this.uri = safeGetString(o.uri); + this.uri = safeGetString(o.uri ?? "") ?? ""; if ("uriChecksum" in o) { this.uriChecksum = o.uriChecksum?.encryptedString; } diff --git a/libs/common/src/models/export/login.export.ts b/libs/common/src/models/export/login.export.ts index b727c614bdf..cee28389716 100644 --- a/libs/common/src/models/export/login.export.ts +++ b/libs/common/src/models/export/login.export.ts @@ -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,19 +34,19 @@ 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 = new EncString(req.username ?? ""); + domain.password = new EncString(req.password ?? ""); + domain.totp = new EncString(req.totp ?? ""); // Fido2credentials are currently not supported for exports. 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) { @@ -63,8 +61,8 @@ export class LoginExport { this.fido2Credentials = o.fido2Credentials.map((key) => new Fido2CredentialExport(key)); } - this.username = safeGetString(o.username); - this.password = safeGetString(o.password); - this.totp = safeGetString(o.totp); + this.username = safeGetString(o.username ?? "") ?? ""; + this.password = safeGetString(o.password ?? "") ?? ""; + this.totp = safeGetString(o.totp ?? "") ?? ""; } } diff --git a/libs/common/src/models/export/password-history.export.ts b/libs/common/src/models/export/password-history.export.ts index f443a2f4ace..f72aba5f32a 100644 --- a/libs/common/src/models/export/password-history.export.ts +++ b/libs/common/src/models/export/password-history.export.ts @@ -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,32 @@ import { safeGetString } from "./utils"; export class PasswordHistoryExport { static template(): PasswordHistoryExport { const req = new PasswordHistoryExport(); - req.password = null; - req.lastUsedDate = null; + req.password = ""; + req.lastUsedDate = new Date(); 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(); return domain; } - password: string; - lastUsedDate: Date = null; + password: string = ""; + lastUsedDate: Date = new 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 ?? new Date(); } } diff --git a/libs/common/src/models/export/secure-note.export.ts b/libs/common/src/models/export/secure-note.export.ts index 358c5a19007..44c66c037f7 100644 --- a/libs/common/src/models/export/secure-note.export.ts +++ b/libs/common/src/models/export/secure-note.export.ts @@ -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) { diff --git a/libs/common/src/models/export/ssh-key.export.ts b/libs/common/src/models/export/ssh-key.export.ts index 9bae57ee620..53cf88b3931 100644 --- a/libs/common/src/models/export/ssh-key.export.ts +++ b/libs/common/src/models/export/ssh-key.export.ts @@ -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"; @@ -30,17 +27,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 ?? "") ?? ""; } }