1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-29 17:38:04 +01:00

lint fixes

This commit is contained in:
Kyle Spearrin 2017-11-04 21:37:35 -04:00
parent 11edb0261b
commit 8e998ff179
5 changed files with 81 additions and 77 deletions

View File

@ -2,41 +2,44 @@ import { CipherString } from '../domain/cipherString';
export default abstract class Domain { export default abstract class Domain {
protected buildDomainModel(model: any, obj: any, map: any, alreadyEncrypted: boolean, notEncList: any = []) { protected buildDomainModel(model: any, obj: any, map: any, alreadyEncrypted: boolean, notEncList: any = []) {
for (var prop in map) { for (const prop in map) {
if (map.hasOwnProperty(prop)) { if (!map.hasOwnProperty(prop)) {
var objProp = obj[(map[prop] || prop)]; continue;
if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) { }
model[prop] = objProp ? objProp : null;
} else { const objProp = obj[(map[prop] || prop)];
model[prop] = objProp ? new CipherString(objProp) : null; if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) {
} model[prop] = objProp ? objProp : null;
} else {
model[prop] = objProp ? new CipherString(objProp) : null;
} }
} }
} }
protected async decryptObj(model: any, self: any, map: any, orgId: string) { protected async decryptObj(model: any, self: any, map: any, orgId: string) {
var promises = []; const promises = [];
for (let prop in map) { for (const prop in map) {
if (!map.hasOwnProperty(prop)) { if (!map.hasOwnProperty(prop)) {
continue; continue;
} }
// tslint:disable-next-line
(function (theProp) { (function (theProp) {
let promise = Promise.resolve().then(function () { const p = Promise.resolve().then(() => {
var mapProp = map[theProp] || theProp; const mapProp = map[theProp] || theProp;
if (self[mapProp]) { if (self[mapProp]) {
return self[mapProp].decrypt(orgId); return self[mapProp].decrypt(orgId);
} }
return null; return null;
}).then(function (val) { }).then((val: any) => {
model[theProp] = val; model[theProp] = val;
return; return;
}); });
promises.push(promise); promises.push(p);
})(prop); })(prop);
} }
await Promise.all(promises); await Promise.all(promises);
return model; return model;
} }
} }

View File

@ -1,7 +1,7 @@
import { CipherString } from './cipherString'; import { FolderData } from '../data/folderData';
import { FolderData } from '../data/folderData'
import Domain from './domain' import { CipherString } from './cipherString';
import Domain from './domain';
class Folder extends Domain { class Folder extends Domain {
id: string; id: string;
@ -9,24 +9,23 @@ class Folder extends Domain {
constructor(obj?: FolderData, alreadyEncrypted: boolean = false) { constructor(obj?: FolderData, alreadyEncrypted: boolean = false) {
super(); super();
if(obj == null) { if (obj == null) {
return; return;
} }
this.buildDomainModel(this, obj, { this.buildDomainModel(this, obj, {
id: null, id: null,
name: null name: null,
}, alreadyEncrypted, ['id']); }, alreadyEncrypted, ['id']);
} }
async decrypt(): Promise<any> { async decrypt(): Promise<any> {
var self = this; const model = {
var model = { id: this.id,
id: self.id
}; };
return await this.decryptObj(model, this, { return await this.decryptObj(model, this, {
name: null name: null,
}, null); }, null);
} }
} }

View File

@ -32,7 +32,7 @@ import ServicesModule from './services/services.module';
import LockModule from './lock/lock.module'; import LockModule from './lock/lock.module';
// Model imports // Model imports
import { Folder } from './models/domain/folder'; import { Folder } from '../../models/domain/folder';
import { AttachmentData } from '../../models/data/attachmentData'; import { AttachmentData } from '../../models/data/attachmentData';
import { CardData } from '../../models/data/cardData'; import { CardData } from '../../models/data/cardData';

View File

@ -82,10 +82,10 @@ export default class ApiService {
const response = await fetch(new Request(this.identityBaseUrl + '/connect/token', { const response = await fetch(new Request(this.identityBaseUrl + '/connect/token', {
body: this.qsStringify(request.toIdentityToken()), body: this.qsStringify(request.toIdentityToken()),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Accept': 'application/json', 'Accept': 'application/json',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -114,9 +114,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/two-factor/send-email-login', { const response = await fetch(new Request(this.baseUrl + '/two-factor/send-email-login', {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -132,10 +132,10 @@ export default class ApiService {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', { const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', {
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Accept: 'application/json', Accept: 'application/json',
Authorization: authHeader, Authorization: authHeader,
}, }),
})); }));
if (response.status === 200) { if (response.status === 200) {
@ -150,9 +150,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/accounts/password-hint', { const response = await fetch(new Request(this.baseUrl + '/accounts/password-hint', {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -166,9 +166,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/accounts/register', { const response = await fetch(new Request(this.baseUrl + '/accounts/register', {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -185,11 +185,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/folders', { const response = await fetch(new Request(this.baseUrl + '/folders', {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': authHeader, 'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -207,11 +207,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { const response = await fetch(new Request(this.baseUrl + '/folders/' + id, {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': authHeader, 'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'PUT', method: 'PUT',
})); }));
@ -228,9 +228,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { const response = await fetch(new Request(this.baseUrl + '/folders/' + id, {
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Authorization: authHeader, Authorization: authHeader,
}, }),
method: 'DELETE', method: 'DELETE',
})); }));
@ -247,11 +247,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers', { const response = await fetch(new Request(this.baseUrl + '/ciphers', {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': authHeader, 'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'POST', method: 'POST',
})); }));
@ -269,11 +269,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
body: JSON.stringify(request), body: JSON.stringify(request),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': authHeader, 'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8', 'Content-Type': 'application/json; charset=utf-8',
}, }),
method: 'PUT', method: 'PUT',
})); }));
@ -290,9 +290,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Authorization: authHeader, Authorization: authHeader,
}, }),
method: 'DELETE', method: 'DELETE',
})); }));
@ -309,10 +309,10 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', {
body: data, body: data,
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Accept: 'application/json', Accept: 'application/json',
Authorization: authHeader, Authorization: authHeader,
}, }),
method: 'POST', method: 'POST',
})); }));
@ -329,9 +329,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, {
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Authorization: authHeader, Authorization: authHeader,
}, }),
method: 'DELETE', method: 'DELETE',
})); }));
@ -347,10 +347,10 @@ export default class ApiService {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/sync', { const response = await fetch(new Request(this.baseUrl + '/sync', {
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
Accept: 'application/json', Accept: 'application/json',
Authorization: authHeader, Authorization: authHeader,
}, }),
})); }));
if (response.status === 200) { if (response.status === 200) {
@ -407,10 +407,10 @@ export default class ApiService {
refresh_token: refreshToken, refresh_token: refreshToken,
}), }),
cache: 'no-cache', cache: 'no-cache',
headers: { headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Accept': 'application/json', 'Accept': 'application/json',
}, }),
method: 'POST', method: 'POST',
})); }));

View File

@ -1,8 +1,10 @@
import { CipherString } from '../models/domain/cipherString'; import { CipherString } from '../models/domain/cipherString';
import { Folder } from '../models/domain/folder'; import { Folder } from '../models/domain/folder';
import { FolderData } from '../models/data/folderData'; import { FolderData } from '../models/data/folderData';
import { FolderResponse } from '../models/response/folderResponse';
import { FolderRequest } from '../models/request/folderRequest'; import { FolderRequest } from '../models/request/folderRequest';
import { FolderResponse } from '../models/response/folderResponse';
import ApiService from './api.service'; import ApiService from './api.service';
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
@ -11,14 +13,14 @@ import UserService from './user.service';
import UtilsService from './utils.service'; import UtilsService from './utils.service';
const Keys = { const Keys = {
foldersPrefix: 'folders_' foldersPrefix: 'folders_',
}; };
export default class FolderService { export default class FolderService {
decryptedFolderCache: any[]; decryptedFolderCache: any[];
constructor(private cryptoService: CryptoService, private userService: UserService, private i18nService: any, private apiService: ApiService) {
constructor(private cryptoService: CryptoService, private userService: UserService,
private i18nService: any, private apiService: ApiService) {
} }
clearCache(): void { clearCache(): void {
@ -31,10 +33,10 @@ export default class FolderService {
return folder; return folder;
} }
async get(id:string): Promise<Folder> { async get(id: string): Promise<Folder> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId); const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null || !folders.has(id)) { if (folders == null || !folders.has(id)) {
return null; return null;
} }
@ -44,7 +46,7 @@ export default class FolderService {
async getAll(): Promise<Folder[]> { async getAll(): Promise<Folder[]> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId); const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
const response:Folder[] = []; const response: Folder[] = [];
folders.forEach((folder) => { folders.forEach((folder) => {
response.push(new Folder(folder)); response.push(new Folder(folder));
}); });
@ -58,17 +60,17 @@ export default class FolderService {
const decFolders: any[] = [{ const decFolders: any[] = [{
id: null, id: null,
name: this.i18nService.noneFolder name: this.i18nService.noneFolder,
}]; }];
const key = await this.cryptoService.getKey(); const key = await this.cryptoService.getKey();
if(key == null) { if (key == null) {
throw new Error('No key.'); throw new Error('No key.');
} }
const promises = []; const promises = [];
const folders = await this.getAll(); const folders = await this.getAll();
for(const folder of folders) { for (const folder of folders) {
promises.push(folder.decrypt().then((f: any) => { promises.push(folder.decrypt().then((f: any) => {
decFolders.push(f); decFolders.push(f);
})); }));
@ -79,11 +81,11 @@ export default class FolderService {
return this.decryptedFolderCache; return this.decryptedFolderCache;
} }
async saveWithServer (folder: Folder): Promise<any> { async saveWithServer(folder: Folder): Promise<any> {
const request = new FolderRequest(folder); const request = new FolderRequest(folder);
let response: FolderResponse; let response: FolderResponse;
if(folder.id == null) { if (folder.id == null) {
response = await this.apiService.postFolder(request); response = await this.apiService.postFolder(request);
folder.id = response.id; folder.id = response.id;
} else { } else {
@ -98,15 +100,15 @@ export default class FolderService {
async upsert(folder: FolderData | FolderData[]): Promise<any> { async upsert(folder: FolderData | FolderData[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
let folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId); let folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null) { if (folders == null) {
folders = new Map<string, FolderData>(); folders = new Map<string, FolderData>();
} }
if(folder instanceof FolderData) { if (folder instanceof FolderData) {
const f = folder as FolderData; const f = folder as FolderData;
folders.set(f.id, f); folders.set(f.id, f);
} else { } else {
for(const f of (folder as FolderData[])) { for (const f of (folder as FolderData[])) {
folders.set(f.id, f); folders.set(f.id, f);
} }
} }
@ -115,29 +117,29 @@ export default class FolderService {
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
} }
async replace (folders: FolderData[]): Promise<any> { async replace(folders: FolderData[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders); await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders);
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
} }
async clear(userId: string): Promise<any> { async clear(userId: string): Promise<any> {
await UtilsService.removeFromStorage(Keys.foldersPrefix + userId); await UtilsService.removeFromStorage(Keys.foldersPrefix + userId);
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
} }
async delete(id: string | string[]): Promise<any> { async delete(id: string | string[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
let folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId); const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null) { if (folders == null) {
return; return;
} }
if(id instanceof String) { if (id instanceof String) {
const i = id as string; const i = id as string;
folders.delete(i); folders.delete(i);
} else { } else {
for(const i of (id as string[])) { for (const i of (id as string[])) {
folders.delete(i); folders.delete(i);
} }
} }