1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

convert data models to jslib

This commit is contained in:
Kyle Spearrin
2018-01-08 15:12:09 -05:00
parent a78b8ec79c
commit 5d39030e05
22 changed files with 58 additions and 330 deletions

View File

@@ -1,20 +0,0 @@
import { Response } from '@bitwarden/jslib';
class AttachmentData {
id: string;
url: string;
fileName: string;
size: number;
sizeName: string;
constructor(response: Response.Attachment) {
this.id = response.id;
this.url = response.url;
this.fileName = response.fileName;
this.size = response.size;
this.sizeName = response.sizeName;
}
}
export { AttachmentData };
(window as any).AttachmentData = AttachmentData;

View File

@@ -1,20 +0,0 @@
class CardData {
cardholderName: string;
brand: string;
number: string;
expMonth: string;
expYear: string;
code: string;
constructor(data: any) {
this.cardholderName = data.CardholderName;
this.brand = data.Brand;
this.number = data.Number;
this.expMonth = data.ExpMonth;
this.expYear = data.ExpYear;
this.code = data.Code;
}
}
export { CardData };
(window as any).CardData = CardData;

View File

@@ -1,85 +0,0 @@
import { Data, Enums, Response } from '@bitwarden/jslib';
import { AttachmentData } from './attachmentData';
import { CardData } from './cardData';
import { FieldData } from './fieldData';
import { IdentityData } from './identityData';
import { LoginData } from './loginData';
import { SecureNoteData } from './secureNoteData';
class CipherData {
id: string;
organizationId: string;
folderId: string;
userId: string;
edit: boolean;
organizationUseTotp: boolean;
favorite: boolean;
revisionDate: string;
type: Enums.CipherType;
sizeName: string;
name: string;
notes: string;
login?: LoginData;
secureNote?: SecureNoteData;
card?: CardData;
identity?: IdentityData;
fields?: FieldData[];
attachments?: AttachmentData[];
collectionIds?: string[];
constructor(response: Response.Cipher, userId: string, collectionIds?: string[]) {
this.id = response.id;
this.organizationId = response.organizationId;
this.folderId = response.folderId;
this.userId = userId;
this.edit = response.edit;
this.organizationUseTotp = response.organizationUseTotp;
this.favorite = response.favorite;
this.revisionDate = response.revisionDate;
this.type = response.type;
if (collectionIds != null) {
this.collectionIds = collectionIds;
} else {
this.collectionIds = response.collectionIds;
}
this.name = response.data.Name;
this.notes = response.data.Notes;
switch (this.type) {
case Enums.CipherType.Login:
this.login = new LoginData(response.data);
break;
case Enums.CipherType.SecureNote:
this.secureNote = new SecureNoteData(response.data);
break;
case Enums.CipherType.Card:
this.card = new CardData(response.data);
break;
case Enums.CipherType.Identity:
this.identity = new IdentityData(response.data);
break;
default:
break;
}
if (response.data.Fields != null) {
this.fields = [];
response.data.Fields.forEach((field: any) => {
this.fields.push(new FieldData(field));
});
}
if (response.attachments != null) {
this.attachments = [];
response.attachments.forEach((attachment) => {
this.attachments.push(new AttachmentData(attachment));
});
}
}
}
export { CipherData };
(window as any).CipherData = CipherData;

View File

@@ -1,16 +0,0 @@
import { Response } from '@bitwarden/jslib';
class CollectionData {
id: string;
organizationId: string;
name: string;
constructor(response: Response.Collection) {
this.id = response.id;
this.organizationId = response.organizationId;
this.name = response.name;
}
}
export { CollectionData };
(window as any).CollectionData = CollectionData;

View File

@@ -1,16 +0,0 @@
import { Enums } from '@bitwarden/jslib';
class FieldData {
type: Enums.FieldType;
name: string;
value: string;
constructor(response: any) {
this.type = response.Type;
this.name = response.Name;
this.value = response.Value;
}
}
export { FieldData };
(window as any).FieldData = FieldData;

View File

@@ -1,18 +0,0 @@
import { Response } from '@bitwarden/jslib';
class FolderData {
id: string;
userId: string;
name: string;
revisionDate: string;
constructor(response: Response.Folder, userId: string) {
this.userId = userId;
this.name = response.name;
this.id = response.id;
this.revisionDate = response.revisionDate;
}
}
export { FolderData };
(window as any).FolderData = FolderData;

View File

@@ -1,44 +0,0 @@
class IdentityData {
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(data: any) {
this.title = data.Title;
this.firstName = data.FirstName;
this.middleName = data.MiddleName;
this.lastName = data.LastName;
this.address1 = data.Address1;
this.address2 = data.Address2;
this.address3 = data.Address3;
this.city = data.City;
this.state = data.State;
this.postalCode = data.PostalCode;
this.country = data.Country;
this.company = data.Company;
this.email = data.Email;
this.phone = data.Phone;
this.ssn = data.SSN;
this.username = data.Username;
this.passportNumber = data.PassportNumber;
this.licenseNumber = data.LicenseNumber;
}
}
export { IdentityData };
(window as any).IdentityData = IdentityData;

View File

@@ -1,16 +0,0 @@
class LoginData {
uri: string;
username: string;
password: string;
totp: string;
constructor(data: any) {
this.uri = data.Uri;
this.username = data.Username;
this.password = data.Password;
this.totp = data.Totp;
}
}
export { LoginData };
(window as any).LoginData = LoginData;

View File

@@ -1,12 +0,0 @@
import { Enums } from '@bitwarden/jslib';
class SecureNoteData {
type: Enums.SecureNoteType;
constructor(data: any) {
this.type = data.Type;
}
}
export { SecureNoteData };
(window as any).SecureNoteData = SecureNoteData;

View File

@@ -1,4 +1,4 @@
import { AttachmentData } from '../data/attachmentData';
import { Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -10,7 +10,7 @@ class Attachment extends Domain {
sizeName: string;
fileName: CipherString;
constructor(obj?: AttachmentData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Attachment, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,4 +1,4 @@
import { CardData } from '../data/cardData';
import { Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -11,7 +11,7 @@ class Card extends Domain {
expYear: CipherString;
code: CipherString;
constructor(obj?: CardData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Card, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,6 +1,4 @@
import { Abstractions, Enums } from '@bitwarden/jslib';
import { CipherData } from '../data/cipherData';
import { Abstractions, Enums, Data } from '@bitwarden/jslib';
import { Attachment } from './attachment';
import { Card } from './card';
@@ -30,7 +28,7 @@ class Cipher extends Domain {
fields: Field[];
collectionIds: string[];
constructor(obj?: CipherData, alreadyEncrypted: boolean = false, localData: any = null) {
constructor(obj?: Data.Cipher, alreadyEncrypted: boolean = false, localData: any = null) {
super();
if (obj == null) {
return;

View File

@@ -1,4 +1,4 @@
import { CollectionData } from '../data/collectionData';
import { Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -8,7 +8,7 @@ class Collection extends Domain {
organizationId: string;
name: CipherString;
constructor(obj?: CollectionData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Collection, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,6 +1,4 @@
import { Enums } from '@bitwarden/jslib';
import { FieldData } from '../data/fieldData';
import { Enums, Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -10,7 +8,7 @@ class Field extends Domain {
vault: CipherString;
type: Enums.FieldType;
constructor(obj?: FieldData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Field, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,4 +1,4 @@
import { IdentityData } from '../data/identityData';
import { Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -23,7 +23,7 @@ class Identity extends Domain {
passportNumber: CipherString;
licenseNumber: CipherString;
constructor(obj?: IdentityData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Identity, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,4 +1,4 @@
import { LoginData } from '../data/loginData';
import { Data } from '@bitwarden/jslib';
import { CipherString } from './cipherString';
import Domain from './domain';
@@ -9,7 +9,7 @@ class Login extends Domain {
password: CipherString;
totp: CipherString;
constructor(obj?: LoginData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.Login, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;

View File

@@ -1,13 +1,11 @@
import { Enums } from '@bitwarden/jslib';
import { SecureNoteData } from '../data/secureNoteData';
import { Enums, Data } from '@bitwarden/jslib';
import Domain from './domain';
class SecureNote extends Domain {
type: Enums.SecureNoteType;
constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) {
constructor(obj?: Data.SecureNote, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;