mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-23 21:31:29 +01:00
move export models to jslib
This commit is contained in:
parent
27566c3fd5
commit
94f103c474
44
src/models/export/card.ts
Normal file
44
src/models/export/card.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
100
src/models/export/cipher.ts
Normal file
100
src/models/export/cipher.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
15
src/models/export/cipherWithIds.ts
Normal file
15
src/models/export/cipherWithIds.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
27
src/models/export/collection.ts
Normal file
27
src/models/export/collection.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
13
src/models/export/collectionWithId.ts
Normal file
13
src/models/export/collectionWithId.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
34
src/models/export/field.ts
Normal file
34
src/models/export/field.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
21
src/models/export/folder.ts
Normal file
21
src/models/export/folder.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
13
src/models/export/folderWithId.ts
Normal file
13
src/models/export/folderWithId.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
92
src/models/export/identity.ts
Normal file
92
src/models/export/identity.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
43
src/models/export/login.ts
Normal file
43
src/models/export/login.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
30
src/models/export/loginUri.ts
Normal file
30
src/models/export/loginUri.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
26
src/models/export/secureNote.ts
Normal file
26
src/models/export/secureNote.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user