|
|
|
|
@ -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;
|
|
|
|
|
|