diff --git a/src/models/export/card.ts b/src/models/export/card.ts new file mode 100644 index 0000000000..fda37089c9 --- /dev/null +++ b/src/models/export/card.ts @@ -0,0 +1,44 @@ +import { CardView } from '../view/cardView'; + +export class Card { + static template(): Card { + const req = new Card(); + req.cardholderName = 'John Doe'; + req.brand = 'visa'; + req.number = '4242424242424242'; + req.expMonth = '04'; + req.expYear = '2023'; + req.code = '123'; + return req; + } + + static toView(req: Card, view = new CardView()) { + view.cardholderName = req.cardholderName; + view.brand = req.brand; + view.number = req.number; + view.expMonth = req.expMonth; + view.expYear = req.expYear; + view.code = req.code; + return view; + } + + cardholderName: string; + brand: string; + number: string; + expMonth: string; + expYear: string; + code: string; + + constructor(o?: CardView) { + if (o == null) { + return; + } + + this.cardholderName = o.cardholderName; + this.brand = o.brand; + this.number = o.number; + this.expMonth = o.expMonth; + this.expYear = o.expYear; + this.code = o.code; + } +} diff --git a/src/models/export/cipher.ts b/src/models/export/cipher.ts new file mode 100644 index 0000000000..82f9326021 --- /dev/null +++ b/src/models/export/cipher.ts @@ -0,0 +1,100 @@ +import { CipherType } from '../../enums/cipherType'; + +import { CipherView } from '../view/cipherView'; + +import { Card } from './card'; +import { Field } from './field'; +import { Identity } from './identity'; +import { Login } from './login'; +import { SecureNote } from './secureNote'; + +export class Cipher { + static template(): Cipher { + const req = new Cipher(); + req.organizationId = 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; + return req; + } + + static toView(req: Cipher, view = new CipherView()) { + view.type = req.type; + view.folderId = req.folderId; + if (view.organizationId == null) { + view.organizationId = req.organizationId; + } + view.name = req.name; + view.notes = req.notes; + view.favorite = req.favorite; + + if (req.fields != null) { + view.fields = req.fields.map((f) => Field.toView(f)); + } + + switch (req.type) { + case CipherType.Login: + view.login = Login.toView(req.login); + break; + case CipherType.SecureNote: + view.secureNote = SecureNote.toView(req.secureNote); + break; + case CipherType.Card: + view.card = Card.toView(req.card); + break; + case CipherType.Identity: + view.identity = Identity.toView(req.identity); + break; + } + + return view; + } + + type: CipherType; + folderId: string; + organizationId: string; + name: string; + notes: string; + favorite: boolean; + fields: Field[]; + login: Login; + secureNote: SecureNote; + card: Card; + identity: Identity; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CipherView) { + this.organizationId = o.organizationId; + this.folderId = o.folderId; + this.type = o.type; + this.name = o.name; + this.notes = o.notes; + this.favorite = o.favorite; + + if (o.fields != null) { + this.fields = o.fields.map((f) => new Field(f)); + } + + switch (o.type) { + case CipherType.Login: + this.login = new Login(o.login); + break; + case CipherType.SecureNote: + this.secureNote = new SecureNote(o.secureNote); + break; + case CipherType.Card: + this.card = new Card(o.card); + break; + case CipherType.Identity: + this.identity = new Identity(o.identity); + break; + } + } +} diff --git a/src/models/export/cipherWithIds.ts b/src/models/export/cipherWithIds.ts new file mode 100644 index 0000000000..a9635b999a --- /dev/null +++ b/src/models/export/cipherWithIds.ts @@ -0,0 +1,15 @@ +import { Cipher } from './cipher'; + +import { CipherView } from '../view/cipherView'; + +export class CipherWithIds extends Cipher { + 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) { + this.id = o.id; + super.build(o); + this.collectionIds = o.collectionIds; + } +} diff --git a/src/models/export/collection.ts b/src/models/export/collection.ts new file mode 100644 index 0000000000..85080e39f7 --- /dev/null +++ b/src/models/export/collection.ts @@ -0,0 +1,27 @@ +import { CollectionView } from '../view/collectionView'; + +export class Collection { + static template(): Collection { + const req = new Collection(); + req.organizationId = '00000000-0000-0000-0000-000000000000'; + req.name = 'Collection name'; + return req; + } + + static toView(req: Collection, view = new CollectionView()) { + view.name = req.name; + if (view.organizationId == null) { + view.organizationId = req.organizationId; + } + return view; + } + + organizationId: string; + name: string; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CollectionView) { + this.organizationId = o.organizationId; + this.name = o.name; + } +} diff --git a/src/models/export/collectionWithId.ts b/src/models/export/collectionWithId.ts new file mode 100644 index 0000000000..10d8181377 --- /dev/null +++ b/src/models/export/collectionWithId.ts @@ -0,0 +1,13 @@ +import { Collection } from './collection'; + +import { CollectionView } from '../view/collectionView'; + +export class CollectionWithId extends Collection { + id: string; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: CollectionView) { + this.id = o.id; + super.build(o); + } +} diff --git a/src/models/export/field.ts b/src/models/export/field.ts new file mode 100644 index 0000000000..3e07c65eed --- /dev/null +++ b/src/models/export/field.ts @@ -0,0 +1,34 @@ +import { FieldType } from '../../enums/fieldType'; + +import { FieldView } from '../view/fieldView'; + +export class Field { + static template(): Field { + const req = new Field(); + req.name = 'Field name'; + req.value = 'Some value'; + req.type = FieldType.Text; + return req; + } + + static toView(req: Field, view = new FieldView()) { + view.type = req.type; + view.value = req.value; + view.name = req.name; + return view; + } + + name: string; + value: string; + type: FieldType; + + constructor(o?: FieldView) { + if (o == null) { + return; + } + + this.name = o.name; + this.value = o.value; + this.type = o.type; + } +} diff --git a/src/models/export/folder.ts b/src/models/export/folder.ts new file mode 100644 index 0000000000..8c2acf093a --- /dev/null +++ b/src/models/export/folder.ts @@ -0,0 +1,21 @@ +import { FolderView } from '../view/folderView'; + +export class Folder { + static template(): Folder { + const req = new Folder(); + req.name = 'Folder name'; + return req; + } + + static toView(req: Folder, view = new FolderView()) { + view.name = req.name; + return view; + } + + name: string; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: FolderView) { + this.name = o.name; + } +} diff --git a/src/models/export/folderWithId.ts b/src/models/export/folderWithId.ts new file mode 100644 index 0000000000..775376d203 --- /dev/null +++ b/src/models/export/folderWithId.ts @@ -0,0 +1,13 @@ +import { Folder } from './folder'; + +import { FolderView } from '../view/folderView'; + +export class FolderWithId extends Folder { + id: string; + + // Use build method instead of ctor so that we can control order of JSON stringify for pretty print + build(o: FolderView) { + this.id = o.id; + super.build(o); + } +} diff --git a/src/models/export/identity.ts b/src/models/export/identity.ts new file mode 100644 index 0000000000..a1aae09850 --- /dev/null +++ b/src/models/export/identity.ts @@ -0,0 +1,92 @@ +import { IdentityView } from '../view/identityView'; + +export class Identity { + static template(): Identity { + const req = new Identity(); + req.title = 'Mr'; + req.firstName = 'John'; + req.middleName = 'William'; + 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'; + req.country = 'US'; + req.company = 'Acme Inc.'; + req.email = 'john@company.com'; + req.phone = '5555551234'; + req.ssn = '000-123-4567'; + req.username = 'jdoe'; + req.passportNumber = 'US-123456789'; + req.licenseNumber = 'D123-12-123-12333'; + return req; + } + + static toView(req: Identity, view = new IdentityView()) { + view.title = req.title; + view.firstName = req.firstName; + view.middleName = req.middleName; + view.lastName = req.lastName; + view.address1 = req.address1; + view.address2 = req.address2; + view.address3 = req.address3; + view.city = req.city; + view.state = req.state; + view.postalCode = req.postalCode; + view.country = req.country; + view.company = req.company; + view.email = req.email; + view.phone = req.phone; + view.ssn = req.ssn; + view.username = req.username; + view.passportNumber = req.passportNumber; + view.licenseNumber = req.licenseNumber; + return view; + } + + 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) { + if (o == null) { + return; + } + + this.title = o.title; + this.firstName = o.firstName; + this.middleName = o.middleName; + this.lastName = o.lastName; + this.address1 = o.address1; + this.address2 = o.address2; + this.address3 = o.address3; + this.city = o.city; + this.state = o.state; + this.postalCode = o.postalCode; + this.country = o.country; + this.company = o.company; + this.email = o.email; + this.phone = o.phone; + this.ssn = o.ssn; + this.username = o.username; + this.passportNumber = o.passportNumber; + this.licenseNumber = o.licenseNumber; + } +} diff --git a/src/models/export/login.ts b/src/models/export/login.ts new file mode 100644 index 0000000000..b5401bc939 --- /dev/null +++ b/src/models/export/login.ts @@ -0,0 +1,43 @@ +import { LoginUri } from './loginUri'; + +import { LoginView } from '../view/loginView'; + +export class Login { + static template(): Login { + const req = new Login(); + req.uris = []; + req.username = 'jdoe'; + req.password = 'myp@ssword123'; + req.totp = 'JBSWY3DPEHPK3PXP'; + return req; + } + + static toView(req: Login, view = new LoginView()) { + if (req.uris != null) { + view.uris = req.uris.map((u) => LoginUri.toView(u)); + } + view.username = req.username; + view.password = req.password; + view.totp = req.totp; + return view; + } + + uris: LoginUri[]; + username: string; + password: string; + totp: string; + + constructor(o?: LoginView) { + if (o == null) { + return; + } + + if (o.uris != null) { + this.uris = o.uris.map((u) => new LoginUri(u)); + } + + this.username = o.username; + this.password = o.password; + this.totp = o.totp; + } +} diff --git a/src/models/export/loginUri.ts b/src/models/export/loginUri.ts new file mode 100644 index 0000000000..94c3bbd032 --- /dev/null +++ b/src/models/export/loginUri.ts @@ -0,0 +1,30 @@ +import { UriMatchType } from '../../enums/uriMatchType'; + +import { LoginUriView } from '../view/loginUriView'; + +export class LoginUri { + static template(): LoginUri { + const req = new LoginUri(); + req.uri = 'https://google.com'; + req.match = null; + return req; + } + + static toView(req: LoginUri, view = new LoginUriView()) { + view.uri = req.uri; + view.match = req.match; + return view; + } + + uri: string; + match: UriMatchType = null; + + constructor(o?: LoginUriView) { + if (o == null) { + return; + } + + this.uri = o.uri; + this.match = o.match; + } +} diff --git a/src/models/export/secureNote.ts b/src/models/export/secureNote.ts new file mode 100644 index 0000000000..c2115fc337 --- /dev/null +++ b/src/models/export/secureNote.ts @@ -0,0 +1,26 @@ +import { SecureNoteType } from '../../enums/secureNoteType'; + +import { SecureNoteView } from '../view/secureNoteView'; + +export class SecureNote { + static template(): SecureNote { + const req = new SecureNote(); + req.type = SecureNoteType.Generic; + return req; + } + + static toView(req: SecureNote, view = new SecureNoteView()) { + view.type = req.type; + return view; + } + + type: SecureNoteType; + + constructor(o?: SecureNoteView) { + if (o == null) { + return; + } + + this.type = o.type; + } +}