From 33deb4cda66b50631d2b7d30c89bd1386b3b1a07 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 17 Dec 2018 10:30:06 -0500 Subject: [PATCH] move export models to jslib --- jslib | 2 +- src/commands/create.command.ts | 6 +- src/commands/edit.command.ts | 6 +- src/commands/get.command.ts | 20 ++--- src/models/card.ts | 44 ---------- src/models/cipher.ts | 100 ---------------------- src/models/collection.ts | 27 ------ src/models/field.ts | 34 -------- src/models/folder.ts | 21 ----- src/models/identity.ts | 92 -------------------- src/models/login.ts | 43 ---------- src/models/loginUri.ts | 30 ------- src/models/response/cipherResponse.ts | 8 +- src/models/response/collectionResponse.ts | 7 +- src/models/response/folderResponse.ts | 7 +- src/models/response/loginResponse.ts | 5 +- src/models/secureNote.ts | 26 ------ 17 files changed, 25 insertions(+), 453 deletions(-) delete mode 100644 src/models/card.ts delete mode 100644 src/models/cipher.ts delete mode 100644 src/models/collection.ts delete mode 100644 src/models/field.ts delete mode 100644 src/models/folder.ts delete mode 100644 src/models/identity.ts delete mode 100644 src/models/login.ts delete mode 100644 src/models/loginUri.ts delete mode 100644 src/models/secureNote.ts diff --git a/jslib b/jslib index 27566c3fd5..94f103c474 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 27566c3fd5a1040112278c7ad0a50c6b8d45e3e4 +Subproject commit 94f103c474655a81f43ad1f108b4408e4ffdcc17 diff --git a/src/commands/create.command.ts b/src/commands/create.command.ts index 086370c711..e7bbbeab57 100644 --- a/src/commands/create.command.ts +++ b/src/commands/create.command.ts @@ -7,13 +7,13 @@ import { CryptoService } from 'jslib/abstractions/crypto.service'; import { FolderService } from 'jslib/abstractions/folder.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 { CipherResponse } from '../models/response/cipherResponse'; import { FolderResponse } from '../models/response/folderResponse'; -import { Cipher } from '../models/cipher'; -import { Folder } from '../models/folder'; - import { CliUtils } from '../utils'; export class CreateCommand { diff --git a/src/commands/edit.command.ts b/src/commands/edit.command.ts index 68a1de4c88..1330ccf99c 100644 --- a/src/commands/edit.command.ts +++ b/src/commands/edit.command.ts @@ -3,13 +3,13 @@ import * as program from 'commander'; import { CipherService } from 'jslib/abstractions/cipher.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 { CipherResponse } from '../models/response/cipherResponse'; import { FolderResponse } from '../models/response/folderResponse'; -import { Cipher } from '../models/cipher'; -import { Folder } from '../models/folder'; - import { CliUtils } from '../utils'; export class EditCommand { diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index b1cc778999..18ead1ba85 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -15,6 +15,16 @@ import { UserService } from 'jslib/abstractions/user.service'; 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 { CollectionView } from 'jslib/models/view/collectionView'; import { FolderView } from 'jslib/models/view/folderView'; @@ -28,16 +38,6 @@ import { OrganizationResponse } from '../models/response/organizationResponse'; import { StringResponse } from '../models/response/stringResponse'; 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 { Utils } from 'jslib/misc/utils'; diff --git a/src/models/card.ts b/src/models/card.ts deleted file mode 100644 index 0e73c763e7..0000000000 --- a/src/models/card.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/cipher.ts b/src/models/cipher.ts deleted file mode 100644 index 354529e62e..0000000000 --- a/src/models/cipher.ts +++ /dev/null @@ -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; - } - } -} diff --git a/src/models/collection.ts b/src/models/collection.ts deleted file mode 100644 index 0585b758ad..0000000000 --- a/src/models/collection.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/field.ts b/src/models/field.ts deleted file mode 100644 index 686ebddac6..0000000000 --- a/src/models/field.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/folder.ts b/src/models/folder.ts deleted file mode 100644 index b0de5025e2..0000000000 --- a/src/models/folder.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/identity.ts b/src/models/identity.ts deleted file mode 100644 index be0a18897d..0000000000 --- a/src/models/identity.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/login.ts b/src/models/login.ts deleted file mode 100644 index 91eef24213..0000000000 --- a/src/models/login.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/loginUri.ts b/src/models/loginUri.ts deleted file mode 100644 index ac4059e333..0000000000 --- a/src/models/loginUri.ts +++ /dev/null @@ -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; - } -} diff --git a/src/models/response/cipherResponse.ts b/src/models/response/cipherResponse.ts index 87202d4da2..afdd64fb97 100644 --- a/src/models/response/cipherResponse.ts +++ b/src/models/response/cipherResponse.ts @@ -1,6 +1,6 @@ +import { CipherWithIds } from 'jslib/models/export/cipherWithIds'; import { CipherView } from 'jslib/models/view/cipherView'; -import { Cipher } from '../cipher'; import { AttachmentResponse } from './attachmentResponse'; import { BaseResponse } from './baseResponse'; import { LoginResponse } from './loginResponse'; @@ -8,23 +8,19 @@ import { PasswordHistoryResponse } from './passwordHistoryResponse'; import { CipherType } from 'jslib/enums'; -export class CipherResponse extends Cipher implements BaseResponse { +export class CipherResponse extends CipherWithIds implements BaseResponse { object: string; - id: string; attachments: AttachmentResponse[]; revisionDate: Date; passwordHistory: PasswordHistoryResponse[]; - collectionIds: string[]; constructor(o: CipherView) { super(); this.object = 'item'; - this.id = o.id; this.build(o); if (o.attachments != null) { this.attachments = o.attachments.map((a) => new AttachmentResponse(a)); } - this.collectionIds = o.collectionIds; this.revisionDate = o.revisionDate; if (o.passwordHistory != null) { this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h)); diff --git a/src/models/response/collectionResponse.ts b/src/models/response/collectionResponse.ts index c83ecff63a..293d474722 100644 --- a/src/models/response/collectionResponse.ts +++ b/src/models/response/collectionResponse.ts @@ -1,17 +1,14 @@ +import { CollectionWithId } from 'jslib/models/export/collectionWithId'; import { CollectionView } from 'jslib/models/view/collectionView'; import { BaseResponse } from './baseResponse'; -import { Collection } from '../collection'; - -export class CollectionResponse extends Collection implements BaseResponse { +export class CollectionResponse extends CollectionWithId implements BaseResponse { object: string; - id: string; constructor(o: CollectionView) { super(); this.object = 'collection'; - this.id = o.id; this.build(o); } } diff --git a/src/models/response/folderResponse.ts b/src/models/response/folderResponse.ts index 0c80f730eb..a543278691 100644 --- a/src/models/response/folderResponse.ts +++ b/src/models/response/folderResponse.ts @@ -1,17 +1,14 @@ +import { FolderWithId } from 'jslib/models/export/folderWithId'; import { FolderView } from 'jslib/models/view/folderView'; import { BaseResponse } from './baseResponse'; -import { Folder } from '../folder'; - -export class FolderResponse extends Folder implements BaseResponse { +export class FolderResponse extends FolderWithId implements BaseResponse { object: string; - id: string; constructor(o: FolderView) { super(); this.object = 'folder'; - this.id = o.id; this.build(o); } } diff --git a/src/models/response/loginResponse.ts b/src/models/response/loginResponse.ts index dc5a96f0f6..1a5278316e 100644 --- a/src/models/response/loginResponse.ts +++ b/src/models/response/loginResponse.ts @@ -1,6 +1,5 @@ -import { Login } from '../login'; - -import { LoginView } from 'jslib/models/view'; +import { Login } from 'jslib/models/export/login'; +import { LoginView } from 'jslib/models/view/loginView'; export class LoginResponse extends Login { passwordRevisionDate: Date; diff --git a/src/models/secureNote.ts b/src/models/secureNote.ts deleted file mode 100644 index 880691f6da..0000000000 --- a/src/models/secureNote.ts +++ /dev/null @@ -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; - } -}