mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
encrypted import for bitwarden json (#220)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { CardView } from '../view/cardView';
|
||||
|
||||
import { Card as CardDomain } from '../domain/card';
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
|
||||
export class Card {
|
||||
static template(): Card {
|
||||
@@ -24,6 +25,16 @@ export class Card {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Card, domain = new CardDomain()) {
|
||||
domain.cardholderName = req.cardholderName != null ? new CipherString(req.cardholderName) : null;
|
||||
domain.brand = req.brand != null ? new CipherString(req.brand) : null;
|
||||
domain.number = req.number != null ? new CipherString(req.number) : null;
|
||||
domain.expMonth = req.expMonth != null ? new CipherString(req.expMonth) : null;
|
||||
domain.expYear = req.expYear != null ? new CipherString(req.expYear) : null;
|
||||
domain.code = req.code != null ? new CipherString(req.code) : null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
cardholderName: string;
|
||||
brand: string;
|
||||
number: string;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { CipherType } from '../../enums/cipherType';
|
||||
import { CipherView } from '../view/cipherView';
|
||||
|
||||
import { Cipher as CipherDomain } from '../domain/cipher';
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
|
||||
import { Card } from './card';
|
||||
import { Field } from './field';
|
||||
@@ -59,6 +60,38 @@ export class Cipher {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Cipher, domain = new CipherDomain()) {
|
||||
domain.type = req.type;
|
||||
domain.folderId = req.folderId;
|
||||
if (domain.organizationId == null) {
|
||||
domain.organizationId = req.organizationId;
|
||||
}
|
||||
domain.name = req.name != null ? new CipherString(req.name) : null;
|
||||
domain.notes = req.notes != null ? new CipherString(req.notes) : null;
|
||||
domain.favorite = req.favorite;
|
||||
|
||||
if (req.fields != null) {
|
||||
domain.fields = req.fields.map((f) => Field.toDomain(f));
|
||||
}
|
||||
|
||||
switch (req.type) {
|
||||
case CipherType.Login:
|
||||
domain.login = Login.toDomain(req.login);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
domain.secureNote = SecureNote.toDomain(req.secureNote);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
domain.card = Card.toDomain(req.card);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
domain.identity = Identity.toDomain(req.identity);
|
||||
break;
|
||||
}
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
type: CipherType;
|
||||
folderId: string;
|
||||
organizationId: string;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { CollectionView } from '../view/collectionView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { Collection as CollectionDomain } from '../domain/collection';
|
||||
|
||||
export class Collection {
|
||||
@@ -20,6 +21,15 @@ export class Collection {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Collection, domain = new CollectionDomain()) {
|
||||
domain.name = req.name != null ? new CipherString(req.name) : null;
|
||||
domain.externalId = req.externalId;
|
||||
if (domain.organizationId == null) {
|
||||
domain.organizationId = req.organizationId;
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
organizationId: string;
|
||||
name: string;
|
||||
externalId: string;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { FieldType } from '../../enums/fieldType';
|
||||
|
||||
import { FieldView } from '../view/fieldView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { Field as FieldDomain } from '../domain/field';
|
||||
|
||||
export class Field {
|
||||
@@ -20,6 +21,13 @@ export class Field {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Field, domain = new FieldDomain()) {
|
||||
domain.type = req.type;
|
||||
domain.value = req.value != null ? new CipherString(req.value) : null;
|
||||
domain.name = req.name != null ? new CipherString(req.name) : null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
name: string;
|
||||
value: string;
|
||||
type: FieldType;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FolderView } from '../view/folderView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { Folder as FolderDomain } from '../domain/folder';
|
||||
|
||||
export class Folder {
|
||||
@@ -14,6 +15,11 @@ export class Folder {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Folder, domain = new FolderDomain()) {
|
||||
domain.name = req.name != null ? new CipherString(req.name) : null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
name: string;
|
||||
|
||||
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { IdentityView } from '../view/identityView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { Identity as IdentityDomain } from '../domain/identity';
|
||||
|
||||
export class Identity {
|
||||
@@ -48,6 +49,28 @@ export class Identity {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Identity, domain = new IdentityDomain()) {
|
||||
domain.title = req.title != null ? new CipherString(req.title) : null;
|
||||
domain.firstName = req.firstName != null ? new CipherString(req.firstName) : null;
|
||||
domain.middleName = req.middleName != null ? new CipherString(req.middleName) : null;
|
||||
domain.lastName = req.lastName != null ? new CipherString(req.lastName) : null;
|
||||
domain.address1 = req.address1 != null ? new CipherString(req.address1) : null;
|
||||
domain.address2 = req.address2 != null ? new CipherString(req.address2) : null;
|
||||
domain.address3 = req.address3 != null ? new CipherString(req.address3) : null;
|
||||
domain.city = req.city != null ? new CipherString(req.city) : null;
|
||||
domain.state = req.state != null ? new CipherString(req.state) : null;
|
||||
domain.postalCode = req.postalCode != null ? new CipherString(req.postalCode) : null;
|
||||
domain.country = req.country != null ? new CipherString(req.country) : null;
|
||||
domain.company = req.company != null ? new CipherString(req.company) : null;
|
||||
domain.email = req.email != null ? new CipherString(req.email) : null;
|
||||
domain.phone = req.phone != null ? new CipherString(req.phone) : null;
|
||||
domain.ssn = req.ssn != null ? new CipherString(req.ssn) : null;
|
||||
domain.username = req.username != null ? new CipherString(req.username) : null;
|
||||
domain.passportNumber = req.passportNumber != null ? new CipherString(req.passportNumber) : null;
|
||||
domain.licenseNumber = req.licenseNumber != null ? new CipherString(req.licenseNumber) : null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
title: string;
|
||||
firstName: string;
|
||||
middleName: string;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { LoginUri } from './loginUri';
|
||||
|
||||
import { LoginView } from '../view/loginView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { Login as LoginDomain } from '../domain/login';
|
||||
|
||||
export class Login {
|
||||
@@ -24,6 +25,16 @@ export class Login {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: Login, domain = new LoginDomain()) {
|
||||
if (req.uris != null) {
|
||||
domain.uris = req.uris.map((u) => LoginUri.toDomain(u));
|
||||
}
|
||||
domain.username = req.username != null ? new CipherString(req.username) : null;
|
||||
domain.password = req.password != null ? new CipherString(req.password) : null;
|
||||
domain.totp = req.totp != null ? new CipherString(req.totp) : null;
|
||||
return domain;
|
||||
}
|
||||
|
||||
uris: LoginUri[];
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { UriMatchType } from '../../enums/uriMatchType';
|
||||
|
||||
import { LoginUriView } from '../view/loginUriView';
|
||||
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { LoginUri as LoginUriDomain } from '../domain/loginUri';
|
||||
|
||||
export class LoginUri {
|
||||
@@ -18,6 +19,12 @@ export class LoginUri {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: LoginUri, domain = new LoginUriDomain()) {
|
||||
domain.uri = req.uri != null ? new CipherString(req.uri) : null;
|
||||
domain.match = req.match;
|
||||
return domain;
|
||||
}
|
||||
|
||||
uri: string;
|
||||
match: UriMatchType = null;
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@ export class SecureNote {
|
||||
return view;
|
||||
}
|
||||
|
||||
static toDomain(req: SecureNote, view = new SecureNoteDomain()) {
|
||||
view.type = req.type;
|
||||
return view;
|
||||
}
|
||||
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(o?: SecureNoteView | SecureNoteDomain) {
|
||||
|
||||
Reference in New Issue
Block a user