mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
typescript models
This commit is contained in:
parent
4b68163cbd
commit
6086bf5812
@ -1,5 +1,6 @@
|
|||||||
import LockService from './services/lockService.js';
|
import LockService from './services/lockService.js';
|
||||||
import UtilsService from './services/utils.service';
|
import UtilsService from './services/utils.service';
|
||||||
|
import * as models from './models/models';
|
||||||
|
|
||||||
var bg_isBackground = true,
|
var bg_isBackground = true,
|
||||||
bg_utilsService,
|
bg_utilsService,
|
||||||
|
@ -68,72 +68,3 @@ window.CipherRequest = function (cipher) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.FolderRequest = function (folder) {
|
|
||||||
this.name = folder.name ? folder.name.encryptedString : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.TokenRequest = function (email, masterPasswordHash, provider, token, remember, device) {
|
|
||||||
this.email = email;
|
|
||||||
this.masterPasswordHash = masterPasswordHash;
|
|
||||||
this.token = token;
|
|
||||||
this.provider = provider;
|
|
||||||
this.remember = remember === true;
|
|
||||||
this.device = null;
|
|
||||||
if (device) {
|
|
||||||
this.device = device;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.TokenRequest.prototype.toIdentityToken = function () {
|
|
||||||
var obj = {
|
|
||||||
grant_type: 'password',
|
|
||||||
username: this.email,
|
|
||||||
password: this.masterPasswordHash,
|
|
||||||
scope: 'api offline_access',
|
|
||||||
client_id: 'browser'
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.device) {
|
|
||||||
obj.deviceType = this.device.type;
|
|
||||||
obj.deviceIdentifier = this.device.identifier;
|
|
||||||
obj.deviceName = this.device.name;
|
|
||||||
obj.devicePushToken = this.device.pushToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.token && this.provider !== null && (typeof this.provider !== 'undefined')) {
|
|
||||||
obj.twoFactorToken = this.token;
|
|
||||||
obj.twoFactorProvider = this.provider;
|
|
||||||
obj.twoFactorRemember = this.remember ? '1' : '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.RegisterRequest = function (email, masterPasswordHash, masterPasswordHint, key) {
|
|
||||||
this.name = null;
|
|
||||||
this.email = email;
|
|
||||||
this.masterPasswordHash = masterPasswordHash;
|
|
||||||
this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null;
|
|
||||||
this.key = key;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.PasswordHintRequest = function (email) {
|
|
||||||
this.email = email;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.TwoFactorEmailRequest = function (email, masterPasswordHash) {
|
|
||||||
this.email = email;
|
|
||||||
this.masterPasswordHash = masterPasswordHash;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.DeviceTokenRequest = function () {
|
|
||||||
this.pushToken = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.DeviceRequest = function (appId, utilsService) {
|
|
||||||
this.type = utilsService.getDeviceType();
|
|
||||||
this.name = utilsService.getBrowser();
|
|
||||||
this.identifier = appId;
|
|
||||||
this.pushToken = null;
|
|
||||||
};
|
|
||||||
|
@ -1,169 +0,0 @@
|
|||||||
window.CipherResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.organizationId = response.OrganizationId;
|
|
||||||
this.folderId = response.FolderId;
|
|
||||||
this.type = response.Type;
|
|
||||||
this.favorite = response.Favorite;
|
|
||||||
this.edit = response.Edit;
|
|
||||||
this.organizationUseTotp = response.OrganizationUseTotp;
|
|
||||||
this.data = response.Data;
|
|
||||||
this.revisionDate = response.RevisionDate;
|
|
||||||
|
|
||||||
if (response.Attachments) {
|
|
||||||
this.attachments = [];
|
|
||||||
for (var i = 0; i < response.Attachments.length; i++) {
|
|
||||||
this.attachments.push(new AttachmentResponse(response.Attachments[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.FolderResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.revisionDate = response.RevisionDate;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ProfileResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.email = response.Email;
|
|
||||||
this.emailVerified = response.EmailVerified;
|
|
||||||
this.masterPasswordHint = response.MasterPasswordHint;
|
|
||||||
this.premium = response.Premium;
|
|
||||||
this.culture = response.Culture;
|
|
||||||
this.twoFactorEnabled = response.TwoFactorEnabled;
|
|
||||||
this.key = response.Key;
|
|
||||||
this.privateKey = response.PrivateKey;
|
|
||||||
this.securityStamp = response.SecurityStamp;
|
|
||||||
|
|
||||||
this.organizations = [];
|
|
||||||
if (response.Organizations) {
|
|
||||||
for (var i = 0; i < response.Organizations.length; i++) {
|
|
||||||
this.organizations.push(new ProfileOrganizationResponse(response.Organizations[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.KeysResponse = function (response) {
|
|
||||||
this.privateKey = response.PrivateKey;
|
|
||||||
this.publicKey = response.PublicKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ProfileOrganizationResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.useGroups = response.UseGroups;
|
|
||||||
this.useDirectory = response.UseDirectory;
|
|
||||||
this.useTotp = response.UseTotp;
|
|
||||||
this.seats = response.Seats;
|
|
||||||
this.maxCollections = response.MaxCollections;
|
|
||||||
this.maxStorageGb = response.MaxStorageGb;
|
|
||||||
this.key = response.Key;
|
|
||||||
this.status = response.Status;
|
|
||||||
this.type = response.Type;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.AttachmentResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.url = response.Url;
|
|
||||||
this.fileName = response.FileName;
|
|
||||||
this.size = response.Size;
|
|
||||||
this.sizeName = response.SizeName;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.IdentityTokenResponse = function (response) {
|
|
||||||
this.accessToken = response.access_token;
|
|
||||||
this.expiresIn = response.expires_in;
|
|
||||||
this.refreshToken = response.refresh_token;
|
|
||||||
this.tokenType = response.token_type;
|
|
||||||
|
|
||||||
this.privateKey = response.PrivateKey;
|
|
||||||
this.key = response.Key;
|
|
||||||
this.twoFactorToken = response.TwoFactorToken;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ListResponse = function (data) {
|
|
||||||
this.data = data;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.ErrorResponse = function (response, identityResponse) {
|
|
||||||
var errorModel = null;
|
|
||||||
if (identityResponse && identityResponse === true && response.responseJSON && response.responseJSON.ErrorModel) {
|
|
||||||
errorModel = response.responseJSON.ErrorModel;
|
|
||||||
}
|
|
||||||
else if (response.responseJSON) {
|
|
||||||
errorModel = response.responseJSON;
|
|
||||||
}
|
|
||||||
else if (response.responseText && response.responseText.indexOf('{') === 0) {
|
|
||||||
errorModel = JSON.parse(response.responseText);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errorModel) {
|
|
||||||
this.message = errorModel.Message;
|
|
||||||
this.validationErrors = errorModel.ValidationErrors;
|
|
||||||
}
|
|
||||||
this.statusCode = response.status;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.DeviceResponse = function (response) {
|
|
||||||
this.id = response.Id;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.identifier = response.Identifier;
|
|
||||||
this.type = response.Type;
|
|
||||||
this.creationDate = response.CreationDate;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.CipherHistoryResponse = function (response) {
|
|
||||||
this.revised = [];
|
|
||||||
|
|
||||||
var revised = response.Revised;
|
|
||||||
for (var i = 0; i < revised.length; i++) {
|
|
||||||
this.revised.push(new CipherResponse(revised[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.deleted = response.Deleted;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.DomainsResponse = function (response) {
|
|
||||||
var GlobalDomainResponse = function (response) {
|
|
||||||
this.type = response.Type;
|
|
||||||
this.domains = response.Domains;
|
|
||||||
this.excluded = response.Excluded;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.equivalentDomains = response.EquivalentDomains;
|
|
||||||
this.globalEquivalentDomains = [];
|
|
||||||
|
|
||||||
var globalEquivalentDomains = response.GlobalEquivalentDomains;
|
|
||||||
if (!globalEquivalentDomains) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < globalEquivalentDomains.length; i++) {
|
|
||||||
this.globalEquivalentDomains.push(new GlobalDomainResponse(globalEquivalentDomains[i]));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.SyncResponse = function (response) {
|
|
||||||
if (response.Profile) {
|
|
||||||
this.profile = new ProfileResponse(response.Profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
var i;
|
|
||||||
this.folders = [];
|
|
||||||
if (response.Folders) {
|
|
||||||
for (i = 0; i < response.Folders.length; i++) {
|
|
||||||
this.folders.push(new FolderResponse(response.Folders[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ciphers = [];
|
|
||||||
if (response.Ciphers) {
|
|
||||||
for (i = 0; i < response.Ciphers.length; i++) {
|
|
||||||
this.ciphers.push(new CipherResponse(response.Ciphers[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.Domains) {
|
|
||||||
this.domains = new DomainsResponse(response.Domains);
|
|
||||||
}
|
|
||||||
};
|
|
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;
|
79
src/models/data/cipherData.ts
Normal file
79
src/models/data/cipherData.ts
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
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: number; // TODO: enum
|
||||||
|
sizeName: string;
|
||||||
|
name: string;
|
||||||
|
notes: string;
|
||||||
|
login?: LoginData;
|
||||||
|
secureNote?: SecureNoteData;
|
||||||
|
card?: CardData;
|
||||||
|
identity?: IdentityData;
|
||||||
|
fields?: FieldData[];
|
||||||
|
attachments?: AttachmentData[];
|
||||||
|
|
||||||
|
constructor(response: CipherResponse, userId: 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;
|
||||||
|
|
||||||
|
this.name = response.data.Name;
|
||||||
|
this.notes = response.data.Notes;
|
||||||
|
|
||||||
|
const constantsService = chrome.extension.getBackgroundPage().bg_constantsService; // TODO: enum
|
||||||
|
switch (this.type) {
|
||||||
|
case constantsService.cipherType.login:
|
||||||
|
this.login = new LoginData(response.data);
|
||||||
|
break;
|
||||||
|
case constantsService.cipherType.secureNote:
|
||||||
|
this.secureNote = new SecureNoteData(response.data);
|
||||||
|
break;
|
||||||
|
case constantsService.cipherType.card:
|
||||||
|
this.card = new CardData(response.data);
|
||||||
|
break;
|
||||||
|
case constantsService.cipherType.identity:
|
||||||
|
this.identity = new IdentityData(response.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.data.Fields) {
|
||||||
|
this.fields = [];
|
||||||
|
for (const field of response.data.Fields) {
|
||||||
|
this.fields.push(new FieldData(field));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.attachments) {
|
||||||
|
this.attachments = [];
|
||||||
|
for (const attachment of response.attachments) {
|
||||||
|
this.attachments.push(new AttachmentData(attachment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CipherData };
|
||||||
|
(window as any).CipherData = CipherData;
|
8
src/models/data/dataModels.ts
Normal file
8
src/models/data/dataModels.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { AttachmentData } from './attachmentData';
|
||||||
|
import { CardData } from './cardData';
|
||||||
|
import { CipherData } from './cipherData';
|
||||||
|
import { FieldData } from './fieldData';
|
||||||
|
import { FolderData } from './folderData';
|
||||||
|
import { IdentityData } from './identityData';
|
||||||
|
import { LoginData } from './loginData';
|
||||||
|
import { SecureNoteData } from './secureNoteData';
|
14
src/models/data/fieldData.ts
Normal file
14
src/models/data/fieldData.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class FieldData {
|
||||||
|
type: number; // TODO: enum
|
||||||
|
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;
|
10
src/models/data/secureNoteData.ts
Normal file
10
src/models/data/secureNoteData.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class SecureNoteData {
|
||||||
|
type: number; // TODO: enum
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.type = data.Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { SecureNoteData };
|
||||||
|
(window as any).SecureNoteData = SecureNoteData;
|
@ -1,119 +0,0 @@
|
|||||||
var FolderData = function (response, userId) {
|
|
||||||
this.id = response.id;
|
|
||||||
this.userId = userId;
|
|
||||||
|
|
||||||
if (response instanceof FolderResponse) {
|
|
||||||
this.name = response.name;
|
|
||||||
}
|
|
||||||
else if (response instanceof CipherResponse) {
|
|
||||||
this.name = response.data.Name;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw 'unsupported instance';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.revisionDate = response.revisionDate;
|
|
||||||
};
|
|
||||||
|
|
||||||
var CipherData = function (response, userId) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
this.name = response.data.Name;
|
|
||||||
this.notes = response.notes = response.data.Notes;
|
|
||||||
|
|
||||||
var constantsService = chrome.extension.getBackgroundPage().bg_constantsService;
|
|
||||||
switch (this.type) {
|
|
||||||
case constantsService.cipherType.login:
|
|
||||||
this.login = new LoginData(response.data);
|
|
||||||
break;
|
|
||||||
case constantsService.cipherType.secureNote:
|
|
||||||
this.secureNote = new SecureNoteData(response.data);
|
|
||||||
break;
|
|
||||||
case constantsService.cipherType.card:
|
|
||||||
this.card = new CardData(response.data);
|
|
||||||
break;
|
|
||||||
case constantsService.cipherType.identity:
|
|
||||||
this.identity = new IdentityData(response.data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var i;
|
|
||||||
if (response.data.Fields) {
|
|
||||||
this.fields = [];
|
|
||||||
for (i = 0; i < response.data.Fields.length; i++) {
|
|
||||||
this.fields.push(new FieldData(response.data.Fields[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.attachments) {
|
|
||||||
this.attachments = [];
|
|
||||||
for (i = 0; i < response.attachments.length; i++) {
|
|
||||||
this.attachments.push(new AttachmentData(response.attachments[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var AttachmentData = function (response) {
|
|
||||||
this.id = response.id;
|
|
||||||
this.url = response.url;
|
|
||||||
this.fileName = response.fileName;
|
|
||||||
this.size = response.size;
|
|
||||||
this.sizeName = response.sizeName;
|
|
||||||
};
|
|
||||||
|
|
||||||
var FieldData = function (response) {
|
|
||||||
this.type = response.Type;
|
|
||||||
this.name = response.Name;
|
|
||||||
this.value = response.Value;
|
|
||||||
};
|
|
||||||
|
|
||||||
var LoginData = function (data) {
|
|
||||||
this.uri = data.Uri;
|
|
||||||
this.username = data.Username;
|
|
||||||
this.password = data.Password;
|
|
||||||
this.totp = data.Totp;
|
|
||||||
};
|
|
||||||
|
|
||||||
var IdentityData = function (data) {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
var SecureNoteData = function (data) {
|
|
||||||
this.type = data.Type;
|
|
||||||
};
|
|
||||||
|
|
||||||
var CardData = function (data) {
|
|
||||||
this.cardholderName = data.CardholderName;
|
|
||||||
this.brand = data.Brand;
|
|
||||||
this.number = data.Number;
|
|
||||||
this.expMonth = data.ExpMonth;
|
|
||||||
this.expYear = data.ExpYear;
|
|
||||||
this.code = data.Code;
|
|
||||||
};
|
|
113
src/models/domain/cipherString.ts
Normal file
113
src/models/domain/cipherString.ts
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
class CipherString {
|
||||||
|
encryptedString?: string;
|
||||||
|
encryptionType?: number; // TODO: enum
|
||||||
|
decryptedValue?: string;
|
||||||
|
cipherText?: string;
|
||||||
|
initializationVector?: string;
|
||||||
|
mac?: string;
|
||||||
|
cryptoService: any; // TODO: type
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.cryptoService = chrome.extension.getBackgroundPage().bg_cryptoService;
|
||||||
|
const constants = chrome.extension.getBackgroundPage().bg_constantsService;
|
||||||
|
|
||||||
|
if (arguments.length >= 2) {
|
||||||
|
// ct and header
|
||||||
|
this.encryptedString = arguments[0] + '.' + arguments[1];
|
||||||
|
|
||||||
|
// iv
|
||||||
|
if (arguments.length > 2 && arguments[2]) {
|
||||||
|
this.encryptedString += ('|' + arguments[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mac
|
||||||
|
if (arguments.length > 3 && arguments[3]) {
|
||||||
|
this.encryptedString += ('|' + arguments[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.encryptionType = arguments[0];
|
||||||
|
this.cipherText = arguments[1];
|
||||||
|
this.initializationVector = arguments[2] || null;
|
||||||
|
this.mac = arguments[3] || null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (arguments.length !== 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.encryptedString = arguments[0];
|
||||||
|
if (!this.encryptedString) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const headerPieces = this.encryptedString.split('.');
|
||||||
|
let encPieces: string[] = null;
|
||||||
|
|
||||||
|
if (headerPieces.length === 2) {
|
||||||
|
try {
|
||||||
|
this.encryptionType = parseInt(headerPieces[0], null);
|
||||||
|
encPieces = headerPieces[1].split('|');
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
encPieces = this.encryptedString.split('|');
|
||||||
|
this.encryptionType = encPieces.length === 3 ? constants.encType.AesCbc128_HmacSha256_B64 :
|
||||||
|
constants.encType.AesCbc256_B64;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.encryptionType) {
|
||||||
|
case constants.encType.AesCbc128_HmacSha256_B64:
|
||||||
|
case constants.encType.AesCbc256_HmacSha256_B64:
|
||||||
|
if (encPieces.length !== 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initializationVector = encPieces[0];
|
||||||
|
this.cipherText = encPieces[1];
|
||||||
|
this.mac = encPieces[2];
|
||||||
|
break;
|
||||||
|
case constants.encType.AesCbc256_B64:
|
||||||
|
if (encPieces.length !== 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initializationVector = encPieces[0];
|
||||||
|
this.cipherText = encPieces[1];
|
||||||
|
break;
|
||||||
|
case constants.encType.Rsa2048_OaepSha256_B64:
|
||||||
|
case constants.encType.Rsa2048_OaepSha1_B64:
|
||||||
|
if (encPieces.length !== 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cipherText = encPieces[0];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decrypt(orgId: string) {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
if (this.decryptedValue) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve(self.decryptedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.cryptoService.getOrgKey(orgId).then((orgKey: any) => {
|
||||||
|
return self.cryptoService.decrypt(self, orgKey);
|
||||||
|
}).then((decValue: any) => {
|
||||||
|
self.decryptedValue = decValue;
|
||||||
|
return self.decryptedValue;
|
||||||
|
}).catch(() => {
|
||||||
|
self.decryptedValue = '[error: cannot decrypt]';
|
||||||
|
return self.decryptedValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CipherString };
|
||||||
|
(window as any).CipherString = CipherString;
|
1
src/models/domain/domainModels.ts
Normal file
1
src/models/domain/domainModels.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import { CipherString } from './cipherString';
|
@ -1,94 +1,3 @@
|
|||||||
var CipherString = function () {
|
|
||||||
this.encryptedString = null;
|
|
||||||
this.encryptionType = null;
|
|
||||||
this.decryptedValue = null;
|
|
||||||
this.cipherText = null;
|
|
||||||
this.initializationVector = null;
|
|
||||||
this.mac = null;
|
|
||||||
this.cryptoService = chrome.extension.getBackgroundPage().bg_cryptoService;
|
|
||||||
|
|
||||||
var constants = chrome.extension.getBackgroundPage().bg_constantsService;
|
|
||||||
|
|
||||||
if (arguments.length >= 2) {
|
|
||||||
// ct and header
|
|
||||||
this.encryptedString = arguments[0] + '.' + arguments[1];
|
|
||||||
|
|
||||||
// iv
|
|
||||||
if (arguments.length > 2 && arguments[2]) {
|
|
||||||
this.encryptedString += ('|' + arguments[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// mac
|
|
||||||
if (arguments.length > 3 && arguments[3]) {
|
|
||||||
this.encryptedString += ('|' + arguments[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.encryptionType = arguments[0];
|
|
||||||
this.cipherText = arguments[1];
|
|
||||||
this.initializationVector = arguments[2] || null;
|
|
||||||
this.mac = arguments[3] || null;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (arguments.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.encryptedString = arguments[0];
|
|
||||||
if (!this.encryptedString) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var headerPieces = this.encryptedString.split('.'),
|
|
||||||
encPieces;
|
|
||||||
|
|
||||||
if (headerPieces.length === 2) {
|
|
||||||
try {
|
|
||||||
this.encryptionType = parseInt(headerPieces[0]);
|
|
||||||
encPieces = headerPieces[1].split('|');
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
encPieces = this.encryptedString.split('|');
|
|
||||||
this.encryptionType = encPieces.length === 3 ? constants.encType.AesCbc128_HmacSha256_B64 :
|
|
||||||
constants.encType.AesCbc256_B64;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (this.encryptionType) {
|
|
||||||
case constants.encType.AesCbc128_HmacSha256_B64:
|
|
||||||
case constants.encType.AesCbc256_HmacSha256_B64:
|
|
||||||
if (encPieces.length !== 3) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initializationVector = encPieces[0];
|
|
||||||
this.cipherText = encPieces[1];
|
|
||||||
this.mac = encPieces[2];
|
|
||||||
break;
|
|
||||||
case constants.encType.AesCbc256_B64:
|
|
||||||
if (encPieces.length !== 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initializationVector = encPieces[0];
|
|
||||||
this.cipherText = encPieces[1];
|
|
||||||
break;
|
|
||||||
case constants.encType.Rsa2048_OaepSha256_B64:
|
|
||||||
case constants.encType.Rsa2048_OaepSha1_B64:
|
|
||||||
if (encPieces.length !== 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cipherText = encPieces[0];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var Cipher = function (obj, alreadyEncrypted, localData) {
|
var Cipher = function (obj, alreadyEncrypted, localData) {
|
||||||
this.constantsService = chrome.extension.getBackgroundPage().bg_constantsService;
|
this.constantsService = chrome.extension.getBackgroundPage().bg_constantsService;
|
||||||
this.utilsService = chrome.extension.getBackgroundPage().bg_utilsService;
|
this.utilsService = chrome.extension.getBackgroundPage().bg_utilsService;
|
||||||
@ -234,23 +143,6 @@ function buildDomainModel(model, obj, map, alreadyEncrypted, notEncList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
CipherString.prototype.decrypt = function (orgId) {
|
|
||||||
if (this.decryptedValue) {
|
|
||||||
return Q(this.decryptedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
return self.cryptoService.getOrgKey(orgId).then(function (orgKey) {
|
|
||||||
return self.cryptoService.decrypt(self, orgKey);
|
|
||||||
}).then(function (decValue) {
|
|
||||||
self.decryptedValue = decValue;
|
|
||||||
return self.decryptedValue;
|
|
||||||
}).catch(function () {
|
|
||||||
self.decryptedValue = '[error: cannot decrypt]';
|
|
||||||
return self.decryptedValue;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Cipher.prototype.decrypt = function () {
|
Cipher.prototype.decrypt = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
4
src/models/models.ts
Normal file
4
src/models/models.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import * as dataModels from './data/dataModels';
|
||||||
|
import * as domainModels from './domain/domainModels';
|
||||||
|
import * as requestModels from './request/requestModels';
|
||||||
|
import * as responseModels from './response/responseModels';
|
16
src/models/request/deviceRequest.ts
Normal file
16
src/models/request/deviceRequest.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class DeviceRequest {
|
||||||
|
type: number; // TODO: enum
|
||||||
|
name: string;
|
||||||
|
identifier: string;
|
||||||
|
pushToken?: string;
|
||||||
|
|
||||||
|
constructor(appId: string, utilsService: any) { // TODO: utils service type
|
||||||
|
this.type = utilsService.getDeviceType();
|
||||||
|
this.name = utilsService.getBrowser();
|
||||||
|
this.identifier = appId;
|
||||||
|
this.pushToken = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DeviceRequest };
|
||||||
|
(window as any).DeviceRequest = DeviceRequest;
|
10
src/models/request/deviceTokenRequest.ts
Normal file
10
src/models/request/deviceTokenRequest.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class DeviceTokenRequest {
|
||||||
|
pushToken: string;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.pushToken = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DeviceTokenRequest };
|
||||||
|
(window as any).DeviceTokenRequest = DeviceTokenRequest;
|
10
src/models/request/folderRequest.ts
Normal file
10
src/models/request/folderRequest.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class FolderRequest {
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
constructor(folder: any) { // TODO: folder type
|
||||||
|
this.name = folder.name ? folder.name.encryptedString : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { FolderRequest };
|
||||||
|
(window as any).FolderRequest = FolderRequest;
|
10
src/models/request/passwordHintRequest.ts
Normal file
10
src/models/request/passwordHintRequest.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class PasswordHintRequest {
|
||||||
|
email: string;
|
||||||
|
|
||||||
|
constructor(email: string) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { PasswordHintRequest };
|
||||||
|
(window as any).PasswordHintRequest = PasswordHintRequest;
|
18
src/models/request/registerRequest.ts
Normal file
18
src/models/request/registerRequest.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class RegisterRequest {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
masterPasswordHash: string;
|
||||||
|
masterPasswordHint: string;
|
||||||
|
key: string;
|
||||||
|
|
||||||
|
constructor(email: string, masterPasswordHash: string, masterPasswordHint: string, key: string) {
|
||||||
|
this.name = null;
|
||||||
|
this.email = email;
|
||||||
|
this.masterPasswordHash = masterPasswordHash;
|
||||||
|
this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null;
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RegisterRequest };
|
||||||
|
(window as any).RegisterRequest = RegisterRequest;
|
7
src/models/request/requestModels.ts
Normal file
7
src/models/request/requestModels.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { DeviceRequest } from './deviceRequest';
|
||||||
|
import { DeviceTokenRequest } from './deviceTokenRequest';
|
||||||
|
import { FolderRequest } from './folderRequest';
|
||||||
|
import { PasswordHintRequest } from './passwordHintRequest';
|
||||||
|
import { RegisterRequest } from './registerRequest';
|
||||||
|
import { TokenRequest } from './tokenRequest';
|
||||||
|
import { TwoFactorEmailRequest } from './twoFactorEmailRequest';
|
46
src/models/request/tokenRequest.ts
Normal file
46
src/models/request/tokenRequest.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
class TokenRequest {
|
||||||
|
email: string;
|
||||||
|
masterPasswordHash: string;
|
||||||
|
token: string;
|
||||||
|
provider: number;
|
||||||
|
remember: boolean;
|
||||||
|
device?: any;
|
||||||
|
|
||||||
|
constructor(email: string, masterPasswordHash: string, provider: number,
|
||||||
|
token: string, remember: boolean, device?: any) {
|
||||||
|
this.email = email;
|
||||||
|
this.masterPasswordHash = masterPasswordHash;
|
||||||
|
this.token = token;
|
||||||
|
this.provider = provider;
|
||||||
|
this.remember = remember;
|
||||||
|
this.device = device ? device : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
toIdentityToken() {
|
||||||
|
const obj: any = {
|
||||||
|
grant_type: 'password',
|
||||||
|
username: this.email,
|
||||||
|
password: this.masterPasswordHash,
|
||||||
|
scope: 'api offline_access',
|
||||||
|
client_id: 'browser',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.device) {
|
||||||
|
obj.deviceType = this.device.type;
|
||||||
|
obj.deviceIdentifier = this.device.identifier;
|
||||||
|
obj.deviceName = this.device.name;
|
||||||
|
obj.devicePushToken = this.device.pushToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.token && this.provider !== null && (typeof this.provider !== 'undefined')) {
|
||||||
|
obj.twoFactorToken = this.token;
|
||||||
|
obj.twoFactorProvider = this.provider;
|
||||||
|
obj.twoFactorRemember = this.remember ? '1' : '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { TokenRequest };
|
||||||
|
(window as any).TokenRequest = TokenRequest;
|
12
src/models/request/twoFactorEmailRequest.ts
Normal file
12
src/models/request/twoFactorEmailRequest.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class TwoFactorEmailRequest {
|
||||||
|
email: string;
|
||||||
|
masterPasswordHash: string;
|
||||||
|
|
||||||
|
constructor(email: string, masterPasswordHash: string) {
|
||||||
|
this.email = email;
|
||||||
|
this.masterPasswordHash = masterPasswordHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { TwoFactorEmailRequest };
|
||||||
|
(window as any).TwoFactorEmailRequest = TwoFactorEmailRequest;
|
18
src/models/response/attachmentResponse.ts
Normal file
18
src/models/response/attachmentResponse.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class AttachmentResponse {
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
fileName: string;
|
||||||
|
size: number;
|
||||||
|
sizeName: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.url = response.Url;
|
||||||
|
this.fileName = response.FileName;
|
||||||
|
this.size = response.Size;
|
||||||
|
this.sizeName = response.SizeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { AttachmentResponse };
|
||||||
|
(window as any).AttachmentResponse = AttachmentResponse;
|
35
src/models/response/cipherResponse.ts
Normal file
35
src/models/response/cipherResponse.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { AttachmentResponse } from './attachmentResponse';
|
||||||
|
|
||||||
|
class CipherResponse {
|
||||||
|
id: string;
|
||||||
|
organizationId: string;
|
||||||
|
folderId: string;
|
||||||
|
type: number;
|
||||||
|
favorite: boolean;
|
||||||
|
edit: boolean;
|
||||||
|
organizationUseTotp: boolean;
|
||||||
|
data: any;
|
||||||
|
revisionDate: string;
|
||||||
|
attachments: AttachmentResponse[] = [];
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.organizationId = response.OrganizationId;
|
||||||
|
this.folderId = response.FolderId;
|
||||||
|
this.type = response.Type;
|
||||||
|
this.favorite = response.Favorite;
|
||||||
|
this.edit = response.Edit;
|
||||||
|
this.organizationUseTotp = response.OrganizationUseTotp;
|
||||||
|
this.data = response.Data;
|
||||||
|
this.revisionDate = response.RevisionDate;
|
||||||
|
|
||||||
|
if (response.Attachments) {
|
||||||
|
for (const attachment of response.Attachments) {
|
||||||
|
this.attachments.push(new AttachmentResponse(attachment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CipherResponse };
|
||||||
|
(window as any).CipherResponse = CipherResponse;
|
18
src/models/response/deviceResponse.ts
Normal file
18
src/models/response/deviceResponse.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class DeviceResponse {
|
||||||
|
id: string;
|
||||||
|
name: number;
|
||||||
|
identifier: string;
|
||||||
|
type: number; // TODO: Convert to enum
|
||||||
|
creationDate: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.identifier = response.Identifier;
|
||||||
|
this.type = response.Type;
|
||||||
|
this.creationDate = response.CreationDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DeviceResponse };
|
||||||
|
(window as any).DeviceResponse = DeviceResponse;
|
20
src/models/response/domainsResponse.ts
Normal file
20
src/models/response/domainsResponse.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { GlobalDomainResponse } from './globalDomainResponse';
|
||||||
|
|
||||||
|
class DomainsResponse {
|
||||||
|
equivalentDomains: string[][];
|
||||||
|
globalEquivalentDomains: GlobalDomainResponse[] = [];
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.equivalentDomains = response.EquivalentDomains;
|
||||||
|
|
||||||
|
this.globalEquivalentDomains = [];
|
||||||
|
if (response.GlobalEquivalentDomains) {
|
||||||
|
for (const domain of response.GlobalEquivalentDomains) {
|
||||||
|
this.globalEquivalentDomains.push(new GlobalDomainResponse(domain));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DomainsResponse };
|
||||||
|
(window as any).DomainsResponse = DomainsResponse;
|
25
src/models/response/errorResponse.ts
Normal file
25
src/models/response/errorResponse.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
class ErrorResponse {
|
||||||
|
message: string;
|
||||||
|
validationErrors: { [key: string]: string[]; };
|
||||||
|
statusCode: number;
|
||||||
|
|
||||||
|
constructor(response: any, identityResponse?: boolean) {
|
||||||
|
let errorModel = null;
|
||||||
|
if (identityResponse && response.responseJSON && response.responseJSON.ErrorModel) {
|
||||||
|
errorModel = response.responseJSON.ErrorModel;
|
||||||
|
} else if (response.responseJSON) {
|
||||||
|
errorModel = response.responseJSON;
|
||||||
|
} else if (response.responseText && response.responseText.indexOf('{') === 0) {
|
||||||
|
errorModel = JSON.parse(response.responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorModel) {
|
||||||
|
this.message = errorModel.Message;
|
||||||
|
this.validationErrors = errorModel.ValidationErrors;
|
||||||
|
}
|
||||||
|
this.statusCode = response.status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ErrorResponse };
|
||||||
|
(window as any).ErrorResponse = ErrorResponse;
|
14
src/models/response/folderResponse.ts
Normal file
14
src/models/response/folderResponse.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class FolderResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
revisionDate: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.revisionDate = response.RevisionDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { FolderResponse };
|
||||||
|
(window as any).FolderResponse = FolderResponse;
|
14
src/models/response/globalDomainResponse.ts
Normal file
14
src/models/response/globalDomainResponse.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class GlobalDomainResponse {
|
||||||
|
type: number;
|
||||||
|
domains: string[];
|
||||||
|
excluded: number[];
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.type = response.Type;
|
||||||
|
this.domains = response.Domains;
|
||||||
|
this.excluded = response.Excluded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { GlobalDomainResponse };
|
||||||
|
(window as any).GlobalDomainResponse = GlobalDomainResponse;
|
24
src/models/response/identityTokenResponse.ts
Normal file
24
src/models/response/identityTokenResponse.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
class IdentityTokenResponse {
|
||||||
|
accessToken: string;
|
||||||
|
expiresIn: number;
|
||||||
|
refreshToken: string;
|
||||||
|
tokenType: string;
|
||||||
|
|
||||||
|
privateKey: string;
|
||||||
|
key: string;
|
||||||
|
twoFactorToken: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.accessToken = response.access_token;
|
||||||
|
this.expiresIn = response.expires_in;
|
||||||
|
this.refreshToken = response.refresh_token;
|
||||||
|
this.tokenType = response.token_type;
|
||||||
|
|
||||||
|
this.privateKey = response.PrivateKey;
|
||||||
|
this.key = response.Key;
|
||||||
|
this.twoFactorToken = response.TwoFactorToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { IdentityTokenResponse };
|
||||||
|
(window as any).IdentityTokenResponse = IdentityTokenResponse;
|
12
src/models/response/keysResponse.ts
Normal file
12
src/models/response/keysResponse.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class KeysResponse {
|
||||||
|
privateKey: string;
|
||||||
|
publicKey: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.privateKey = response.PrivateKey;
|
||||||
|
this.publicKey = response.PublicKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { KeysResponse };
|
||||||
|
(window as any).KeysResponse = KeysResponse;
|
10
src/models/response/listResponse.ts
Normal file
10
src/models/response/listResponse.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class ListResponse {
|
||||||
|
data: any;
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ListResponse };
|
||||||
|
(window as any).ListResponse = ListResponse;
|
30
src/models/response/profileOrganizationResponse.ts
Normal file
30
src/models/response/profileOrganizationResponse.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
class ProfileOrganizationResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
useGroups: boolean;
|
||||||
|
useDirectory: boolean;
|
||||||
|
useTotp: boolean;
|
||||||
|
seats: number;
|
||||||
|
maxCollections: number;
|
||||||
|
maxStorageGb?: number;
|
||||||
|
key: string;
|
||||||
|
status: number; // TODO: map to enum
|
||||||
|
type: number; // TODO: map to enum
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.useGroups = response.UseGroups;
|
||||||
|
this.useDirectory = response.UseDirectory;
|
||||||
|
this.useTotp = response.UseTotp;
|
||||||
|
this.seats = response.Seats;
|
||||||
|
this.maxCollections = response.MaxCollections;
|
||||||
|
this.maxStorageGb = response.MaxStorageGb;
|
||||||
|
this.key = response.Key;
|
||||||
|
this.status = response.Status;
|
||||||
|
this.type = response.Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ProfileOrganizationResponse };
|
||||||
|
(window as any).ProfileOrganizationResponse = ProfileOrganizationResponse;
|
39
src/models/response/profileResponse.ts
Normal file
39
src/models/response/profileResponse.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { ProfileOrganizationResponse } from './profileOrganizationResponse';
|
||||||
|
|
||||||
|
class ProfileResponse {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
emailVerified: boolean;
|
||||||
|
masterPasswordHint: string;
|
||||||
|
premium: boolean;
|
||||||
|
culture: string;
|
||||||
|
twoFactorEnabled: boolean;
|
||||||
|
key: string;
|
||||||
|
privateKey: string;
|
||||||
|
securityStamp: string;
|
||||||
|
organizations: ProfileOrganizationResponse[] = [];
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.id = response.Id;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.email = response.Email;
|
||||||
|
this.emailVerified = response.EmailVerified;
|
||||||
|
this.masterPasswordHint = response.MasterPasswordHint;
|
||||||
|
this.premium = response.Premium;
|
||||||
|
this.culture = response.Culture;
|
||||||
|
this.twoFactorEnabled = response.TwoFactorEnabled;
|
||||||
|
this.key = response.Key;
|
||||||
|
this.privateKey = response.PrivateKey;
|
||||||
|
this.securityStamp = response.SecurityStamp;
|
||||||
|
|
||||||
|
if (response.Organizations) {
|
||||||
|
for (const org of response.Organizations) {
|
||||||
|
this.organizations.push(new ProfileOrganizationResponse(org));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ProfileResponse };
|
||||||
|
(window as any).ProfileResponse = ProfileResponse;
|
13
src/models/response/responseModels.ts
Normal file
13
src/models/response/responseModels.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { AttachmentResponse } from './attachmentResponse';
|
||||||
|
import { CipherResponse } from './cipherResponse';
|
||||||
|
import { DeviceResponse } from './deviceResponse';
|
||||||
|
import { DomainsResponse } from './domainsResponse';
|
||||||
|
import { ErrorResponse } from './errorResponse';
|
||||||
|
import { FolderResponse } from './folderResponse';
|
||||||
|
import { GlobalDomainResponse } from './globalDomainResponse';
|
||||||
|
import { IdentityTokenResponse } from './identityTokenResponse';
|
||||||
|
import { KeysResponse } from './keysResponse';
|
||||||
|
import { ListResponse } from './listResponse';
|
||||||
|
import { ProfileOrganizationResponse } from './profileOrganizationResponse';
|
||||||
|
import { ProfileResponse } from './profileResponse';
|
||||||
|
import { SyncResponse } from './syncResponse';
|
36
src/models/response/syncResponse.ts
Normal file
36
src/models/response/syncResponse.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { CipherResponse } from './cipherResponse';
|
||||||
|
import { DomainsResponse } from './domainsResponse';
|
||||||
|
import { FolderResponse } from './folderResponse';
|
||||||
|
import { ProfileResponse } from './profileResponse';
|
||||||
|
|
||||||
|
class SyncResponse {
|
||||||
|
profile?: ProfileResponse;
|
||||||
|
folders: FolderResponse[] = [];
|
||||||
|
ciphers: CipherResponse[] = [];
|
||||||
|
domains?: DomainsResponse;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
if (response.Profile) {
|
||||||
|
this.profile = new ProfileResponse(response.Profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Folders) {
|
||||||
|
for (const folder of response.Folders) {
|
||||||
|
this.folders.push(new FolderResponse(folder));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Ciphers) {
|
||||||
|
for (const cipher of response.Ciphers) {
|
||||||
|
this.ciphers.push(new CipherResponse(cipher));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.Domains) {
|
||||||
|
this.domains = new DomainsResponse(response.Domains);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { SyncResponse };
|
||||||
|
(window as any).SyncResponse = SyncResponse;
|
@ -22,8 +22,6 @@ require('../../scripts/duo.js');
|
|||||||
require('../../scripts/u2f.js');
|
require('../../scripts/u2f.js');
|
||||||
|
|
||||||
require('../../models/api/requestModels.js');
|
require('../../models/api/requestModels.js');
|
||||||
require('../../models/api/responseModels.js');
|
|
||||||
require('../../models/dataModels.js');
|
|
||||||
require('../../models/domainModels.js');
|
require('../../models/domainModels.js');
|
||||||
|
|
||||||
require('../less/libs.less');
|
require('../less/libs.less');
|
||||||
@ -31,6 +29,8 @@ require('../less/popup.less');
|
|||||||
|
|
||||||
import ComponentsModule from './components/components.module';
|
import ComponentsModule from './components/components.module';
|
||||||
|
|
||||||
|
import * as models from '../../models/models';
|
||||||
|
|
||||||
angular
|
angular
|
||||||
.module('bit', [
|
.module('bit', [
|
||||||
'ui.router',
|
'ui.router',
|
||||||
@ -103,6 +103,6 @@ require('./lock/lockModule.js');
|
|||||||
require('./lock/lockController.js');
|
require('./lock/lockController.js');
|
||||||
|
|
||||||
// Bootstrap the angular application
|
// Bootstrap the angular application
|
||||||
angular.element(function() {
|
angular.element(function () {
|
||||||
angular.bootstrap(document, ['bit']);
|
angular.bootstrap(document, ['bit']);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user