1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-06 02:23:44 +00:00

typescript models

This commit is contained in:
Kyle Spearrin
2017-11-01 10:27:07 -04:00
parent 4b68163cbd
commit 6086bf5812
40 changed files with 788 additions and 468 deletions

View 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;

View File

@@ -0,0 +1,10 @@
class DeviceTokenRequest {
pushToken: string;
constructor() {
this.pushToken = null;
}
}
export { DeviceTokenRequest };
(window as any).DeviceTokenRequest = DeviceTokenRequest;

View 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;

View File

@@ -0,0 +1,10 @@
class PasswordHintRequest {
email: string;
constructor(email: string) {
this.email = email;
}
}
export { PasswordHintRequest };
(window as any).PasswordHintRequest = PasswordHintRequest;

View 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;

View 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';

View 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;

View 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;