1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

move export models to jslib

This commit is contained in:
Kyle Spearrin 2018-12-17 10:30:06 -05:00
parent 9888f699ec
commit 33deb4cda6
17 changed files with 25 additions and 453 deletions

2
jslib

@ -1 +1 @@
Subproject commit 27566c3fd5a1040112278c7ad0a50c6b8d45e3e4 Subproject commit 94f103c474655a81f43ad1f108b4408e4ffdcc17

View File

@ -7,13 +7,13 @@ import { CryptoService } from 'jslib/abstractions/crypto.service';
import { FolderService } from 'jslib/abstractions/folder.service'; import { FolderService } from 'jslib/abstractions/folder.service';
import { UserService } from 'jslib/abstractions/user.service'; import { UserService } from 'jslib/abstractions/user.service';
import { Cipher } from 'jslib/models/export/cipher';
import { Folder } from 'jslib/models/export/folder';
import { Response } from '../models/response'; import { Response } from '../models/response';
import { CipherResponse } from '../models/response/cipherResponse'; import { CipherResponse } from '../models/response/cipherResponse';
import { FolderResponse } from '../models/response/folderResponse'; import { FolderResponse } from '../models/response/folderResponse';
import { Cipher } from '../models/cipher';
import { Folder } from '../models/folder';
import { CliUtils } from '../utils'; import { CliUtils } from '../utils';
export class CreateCommand { export class CreateCommand {

View File

@ -3,13 +3,13 @@ import * as program from 'commander';
import { CipherService } from 'jslib/abstractions/cipher.service'; import { CipherService } from 'jslib/abstractions/cipher.service';
import { FolderService } from 'jslib/services/folder.service'; import { FolderService } from 'jslib/services/folder.service';
import { Cipher } from 'jslib/models/export/cipher';
import { Folder } from 'jslib/models/export/folder';
import { Response } from '../models/response'; import { Response } from '../models/response';
import { CipherResponse } from '../models/response/cipherResponse'; import { CipherResponse } from '../models/response/cipherResponse';
import { FolderResponse } from '../models/response/folderResponse'; import { FolderResponse } from '../models/response/folderResponse';
import { Cipher } from '../models/cipher';
import { Folder } from '../models/folder';
import { CliUtils } from '../utils'; import { CliUtils } from '../utils';
export class EditCommand { export class EditCommand {

View File

@ -15,6 +15,16 @@ import { UserService } from 'jslib/abstractions/user.service';
import { Organization } from 'jslib/models/domain/organization'; import { Organization } from 'jslib/models/domain/organization';
import { Card } from 'jslib/models/export/card';
import { Cipher } from 'jslib/models/export/cipher';
import { Collection } from 'jslib/models/export/collection';
import { Field } from 'jslib/models/export/field';
import { Folder } from 'jslib/models/export/folder';
import { Identity } from 'jslib/models/export/identity';
import { Login } from 'jslib/models/export/login';
import { LoginUri } from 'jslib/models/export/loginUri';
import { SecureNote } from 'jslib/models/export/secureNote';
import { CipherView } from 'jslib/models/view/cipherView'; import { CipherView } from 'jslib/models/view/cipherView';
import { CollectionView } from 'jslib/models/view/collectionView'; import { CollectionView } from 'jslib/models/view/collectionView';
import { FolderView } from 'jslib/models/view/folderView'; import { FolderView } from 'jslib/models/view/folderView';
@ -28,16 +38,6 @@ import { OrganizationResponse } from '../models/response/organizationResponse';
import { StringResponse } from '../models/response/stringResponse'; import { StringResponse } from '../models/response/stringResponse';
import { TemplateResponse } from '../models/response/templateResponse'; import { TemplateResponse } from '../models/response/templateResponse';
import { Card } from '../models/card';
import { Cipher } from '../models/cipher';
import { Collection } from '../models/collection';
import { Field } from '../models/field';
import { Folder } from '../models/folder';
import { Identity } from '../models/identity';
import { Login } from '../models/login';
import { LoginUri } from '../models/loginUri';
import { SecureNote } from '../models/secureNote';
import { CliUtils } from '../utils'; import { CliUtils } from '../utils';
import { Utils } from 'jslib/misc/utils'; import { Utils } from 'jslib/misc/utils';

View File

@ -1,44 +0,0 @@
import { CardView } from 'jslib/models/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;
}
}

View File

@ -1,100 +0,0 @@
import { CipherType } from 'jslib/enums/cipherType';
import { CipherView } from 'jslib/models/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;
}
}
}

View File

@ -1,27 +0,0 @@
import { CollectionView } from 'jslib/models/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;
}
}

View File

@ -1,34 +0,0 @@
import { FieldType } from 'jslib/enums/fieldType';
import { FieldView } from 'jslib/models/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;
}
}

View File

@ -1,21 +0,0 @@
import { FolderView } from 'jslib/models/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;
}
}

View File

@ -1,92 +0,0 @@
import { IdentityView } from 'jslib/models/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;
}
}

View File

@ -1,43 +0,0 @@
import { LoginUri } from './loginUri';
import { LoginView } from 'jslib/models/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;
}
}

View File

@ -1,30 +0,0 @@
import { UriMatchType } from 'jslib/enums/uriMatchType';
import { LoginUriView } from 'jslib/models/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;
}
}

View File

@ -1,6 +1,6 @@
import { CipherWithIds } from 'jslib/models/export/cipherWithIds';
import { CipherView } from 'jslib/models/view/cipherView'; import { CipherView } from 'jslib/models/view/cipherView';
import { Cipher } from '../cipher';
import { AttachmentResponse } from './attachmentResponse'; import { AttachmentResponse } from './attachmentResponse';
import { BaseResponse } from './baseResponse'; import { BaseResponse } from './baseResponse';
import { LoginResponse } from './loginResponse'; import { LoginResponse } from './loginResponse';
@ -8,23 +8,19 @@ import { PasswordHistoryResponse } from './passwordHistoryResponse';
import { CipherType } from 'jslib/enums'; import { CipherType } from 'jslib/enums';
export class CipherResponse extends Cipher implements BaseResponse { export class CipherResponse extends CipherWithIds implements BaseResponse {
object: string; object: string;
id: string;
attachments: AttachmentResponse[]; attachments: AttachmentResponse[];
revisionDate: Date; revisionDate: Date;
passwordHistory: PasswordHistoryResponse[]; passwordHistory: PasswordHistoryResponse[];
collectionIds: string[];
constructor(o: CipherView) { constructor(o: CipherView) {
super(); super();
this.object = 'item'; this.object = 'item';
this.id = o.id;
this.build(o); this.build(o);
if (o.attachments != null) { if (o.attachments != null) {
this.attachments = o.attachments.map((a) => new AttachmentResponse(a)); this.attachments = o.attachments.map((a) => new AttachmentResponse(a));
} }
this.collectionIds = o.collectionIds;
this.revisionDate = o.revisionDate; this.revisionDate = o.revisionDate;
if (o.passwordHistory != null) { if (o.passwordHistory != null) {
this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h)); this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h));

View File

@ -1,17 +1,14 @@
import { CollectionWithId } from 'jslib/models/export/collectionWithId';
import { CollectionView } from 'jslib/models/view/collectionView'; import { CollectionView } from 'jslib/models/view/collectionView';
import { BaseResponse } from './baseResponse'; import { BaseResponse } from './baseResponse';
import { Collection } from '../collection'; export class CollectionResponse extends CollectionWithId implements BaseResponse {
export class CollectionResponse extends Collection implements BaseResponse {
object: string; object: string;
id: string;
constructor(o: CollectionView) { constructor(o: CollectionView) {
super(); super();
this.object = 'collection'; this.object = 'collection';
this.id = o.id;
this.build(o); this.build(o);
} }
} }

View File

@ -1,17 +1,14 @@
import { FolderWithId } from 'jslib/models/export/folderWithId';
import { FolderView } from 'jslib/models/view/folderView'; import { FolderView } from 'jslib/models/view/folderView';
import { BaseResponse } from './baseResponse'; import { BaseResponse } from './baseResponse';
import { Folder } from '../folder'; export class FolderResponse extends FolderWithId implements BaseResponse {
export class FolderResponse extends Folder implements BaseResponse {
object: string; object: string;
id: string;
constructor(o: FolderView) { constructor(o: FolderView) {
super(); super();
this.object = 'folder'; this.object = 'folder';
this.id = o.id;
this.build(o); this.build(o);
} }
} }

View File

@ -1,6 +1,5 @@
import { Login } from '../login'; import { Login } from 'jslib/models/export/login';
import { LoginView } from 'jslib/models/view/loginView';
import { LoginView } from 'jslib/models/view';
export class LoginResponse extends Login { export class LoginResponse extends Login {
passwordRevisionDate: Date; passwordRevisionDate: Date;

View File

@ -1,26 +0,0 @@
import { SecureNoteType } from 'jslib/enums/secureNoteType';
import { SecureNoteView } from 'jslib/models/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;
}
}