mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
copy common ts code over from browser repo
This commit is contained in:
20
src/models/data/attachmentData.ts
Normal file
20
src/models/data/attachmentData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { AttachmentResponse } from '../response/attachmentResponse';
|
||||
|
||||
class AttachmentData {
|
||||
id: string;
|
||||
url: string;
|
||||
fileName: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
|
||||
constructor(response: AttachmentResponse) {
|
||||
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;
|
||||
20
src/models/data/cardData.ts
Normal file
20
src/models/data/cardData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
87
src/models/data/cipherData.ts
Normal file
87
src/models/data/cipherData.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { CipherType } from '../../enums/cipherType.enum';
|
||||
|
||||
import { AttachmentData } from './attachmentData';
|
||||
import { CardData } from './cardData';
|
||||
import { FieldData } from './fieldData';
|
||||
import { IdentityData } from './identityData';
|
||||
import { LoginData } from './loginData';
|
||||
import { SecureNoteData } from './secureNoteData';
|
||||
|
||||
import { CipherResponse } from '../response/cipherResponse';
|
||||
|
||||
class CipherData {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
folderId: string;
|
||||
userId: string;
|
||||
edit: boolean;
|
||||
organizationUseTotp: boolean;
|
||||
favorite: boolean;
|
||||
revisionDate: string;
|
||||
type: CipherType;
|
||||
sizeName: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
login?: LoginData;
|
||||
secureNote?: SecureNoteData;
|
||||
card?: CardData;
|
||||
identity?: IdentityData;
|
||||
fields?: FieldData[];
|
||||
attachments?: AttachmentData[];
|
||||
collectionIds?: string[];
|
||||
|
||||
constructor(response: CipherResponse, 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 CipherType.Login:
|
||||
this.login = new LoginData(response.data);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.secureNote = new SecureNoteData(response.data);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.card = new CardData(response.data);
|
||||
break;
|
||||
case 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;
|
||||
16
src/models/data/collectionData.ts
Normal file
16
src/models/data/collectionData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { CollectionResponse } from '../response/collectionResponse';
|
||||
|
||||
class CollectionData {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
|
||||
constructor(response: CollectionResponse) {
|
||||
this.id = response.id;
|
||||
this.organizationId = response.organizationId;
|
||||
this.name = response.name;
|
||||
}
|
||||
}
|
||||
|
||||
export { CollectionData };
|
||||
(window as any).CollectionData = CollectionData;
|
||||
16
src/models/data/fieldData.ts
Normal file
16
src/models/data/fieldData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { FieldType } from '../../enums/fieldType.enum';
|
||||
|
||||
class FieldData {
|
||||
type: 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;
|
||||
18
src/models/data/folderData.ts
Normal file
18
src/models/data/folderData.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { FolderResponse } from '../response/folderResponse';
|
||||
|
||||
class FolderData {
|
||||
id: string;
|
||||
userId: string;
|
||||
name: string;
|
||||
revisionDate: string;
|
||||
|
||||
constructor(response: FolderResponse, userId: string) {
|
||||
this.userId = userId;
|
||||
this.name = response.name;
|
||||
this.id = response.id;
|
||||
this.revisionDate = response.revisionDate;
|
||||
}
|
||||
}
|
||||
|
||||
export { FolderData };
|
||||
(window as any).FolderData = FolderData;
|
||||
44
src/models/data/identityData.ts
Normal file
44
src/models/data/identityData.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
16
src/models/data/loginData.ts
Normal file
16
src/models/data/loginData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
12
src/models/data/secureNoteData.ts
Normal file
12
src/models/data/secureNoteData.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { SecureNoteType } from '../../enums/secureNoteType.enum';
|
||||
|
||||
class SecureNoteData {
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(data: any) {
|
||||
this.type = data.Type;
|
||||
}
|
||||
}
|
||||
|
||||
export { SecureNoteData };
|
||||
(window as any).SecureNoteData = SecureNoteData;
|
||||
Reference in New Issue
Block a user