From 8e998ff179352f76e5e3cfba79bc473738357064 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 4 Nov 2017 21:37:35 -0400 Subject: [PATCH] lint fixes --- src/models/domain/domain.ts | 35 +++++++++++--------- src/models/domain/folder.ts | 17 +++++----- src/popup/app/app.js | 2 +- src/services/api.service.ts | 60 +++++++++++++++++----------------- src/services/folder.service.ts | 44 +++++++++++++------------ 5 files changed, 81 insertions(+), 77 deletions(-) diff --git a/src/models/domain/domain.ts b/src/models/domain/domain.ts index 4c565967bf4..fcf3341d45c 100644 --- a/src/models/domain/domain.ts +++ b/src/models/domain/domain.ts @@ -2,41 +2,44 @@ import { CipherString } from '../domain/cipherString'; export default abstract class Domain { protected buildDomainModel(model: any, obj: any, map: any, alreadyEncrypted: boolean, notEncList: any = []) { - for (var prop in map) { - if (map.hasOwnProperty(prop)) { - var objProp = obj[(map[prop] || prop)]; - if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) { - model[prop] = objProp ? objProp : null; - } else { - model[prop] = objProp ? new CipherString(objProp) : null; - } + for (const prop in map) { + if (!map.hasOwnProperty(prop)) { + continue; + } + + const objProp = obj[(map[prop] || prop)]; + 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) { - var promises = []; - for (let prop in map) { + const promises = []; + for (const prop in map) { if (!map.hasOwnProperty(prop)) { continue; } - + + // tslint:disable-next-line (function (theProp) { - let promise = Promise.resolve().then(function () { - var mapProp = map[theProp] || theProp; + const p = Promise.resolve().then(() => { + const mapProp = map[theProp] || theProp; if (self[mapProp]) { return self[mapProp].decrypt(orgId); } return null; - }).then(function (val) { + }).then((val: any) => { model[theProp] = val; return; }); - promises.push(promise); + promises.push(p); })(prop); } await Promise.all(promises); return model; } -} \ No newline at end of file +} diff --git a/src/models/domain/folder.ts b/src/models/domain/folder.ts index 7c8ca2a254d..63f4c222292 100644 --- a/src/models/domain/folder.ts +++ b/src/models/domain/folder.ts @@ -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 { id: string; @@ -9,24 +9,23 @@ class Folder extends Domain { constructor(obj?: FolderData, alreadyEncrypted: boolean = false) { super(); - if(obj == null) { + if (obj == null) { return; } this.buildDomainModel(this, obj, { id: null, - name: null + name: null, }, alreadyEncrypted, ['id']); } async decrypt(): Promise { - var self = this; - var model = { - id: self.id + const model = { + id: this.id, }; return await this.decryptObj(model, this, { - name: null + name: null, }, null); } } diff --git a/src/popup/app/app.js b/src/popup/app/app.js index a49b67c03c2..9141bfd4e91 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -32,7 +32,7 @@ import ServicesModule from './services/services.module'; import LockModule from './lock/lock.module'; // Model imports -import { Folder } from './models/domain/folder'; +import { Folder } from '../../models/domain/folder'; import { AttachmentData } from '../../models/data/attachmentData'; import { CardData } from '../../models/data/cardData'; diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 805ec5d45fc..f4cf5e3ac9d 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -82,10 +82,10 @@ export default class ApiService { const response = await fetch(new Request(this.identityBaseUrl + '/connect/token', { body: this.qsStringify(request.toIdentityToken()), cache: 'no-cache', - headers: { + headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Accept': 'application/json', - }, + }), method: 'POST', })); @@ -114,9 +114,9 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/two-factor/send-email-login', { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'POST', })); @@ -132,10 +132,10 @@ export default class ApiService { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', { cache: 'no-cache', - headers: { + headers: new Headers({ Accept: 'application/json', Authorization: authHeader, - }, + }), })); if (response.status === 200) { @@ -150,9 +150,9 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/accounts/password-hint', { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'POST', })); @@ -166,9 +166,9 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/accounts/register', { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'POST', })); @@ -185,11 +185,11 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/folders', { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'POST', })); @@ -207,11 +207,11 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'PUT', })); @@ -228,9 +228,9 @@ export default class ApiService { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/folders/' + id, { cache: 'no-cache', - headers: { + headers: new Headers({ Authorization: authHeader, - }, + }), method: 'DELETE', })); @@ -247,11 +247,11 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/ciphers', { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'POST', })); @@ -269,11 +269,11 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { body: JSON.stringify(request), cache: 'no-cache', - headers: { + headers: new Headers({ 'Accept': 'application/json', 'Authorization': authHeader, 'Content-Type': 'application/json; charset=utf-8', - }, + }), method: 'PUT', })); @@ -290,9 +290,9 @@ export default class ApiService { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, { cache: 'no-cache', - headers: { + headers: new Headers({ Authorization: authHeader, - }, + }), method: 'DELETE', })); @@ -309,10 +309,10 @@ export default class ApiService { const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', { body: data, cache: 'no-cache', - headers: { + headers: new Headers({ Accept: 'application/json', Authorization: authHeader, - }, + }), method: 'POST', })); @@ -329,9 +329,9 @@ export default class ApiService { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, { cache: 'no-cache', - headers: { + headers: new Headers({ Authorization: authHeader, - }, + }), method: 'DELETE', })); @@ -347,10 +347,10 @@ export default class ApiService { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.baseUrl + '/sync', { cache: 'no-cache', - headers: { + headers: new Headers({ Accept: 'application/json', Authorization: authHeader, - }, + }), })); if (response.status === 200) { @@ -407,10 +407,10 @@ export default class ApiService { refresh_token: refreshToken, }), cache: 'no-cache', - headers: { + headers: new Headers({ 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Accept': 'application/json', - }, + }), method: 'POST', })); diff --git a/src/services/folder.service.ts b/src/services/folder.service.ts index 7761a1b68eb..e8502d14274 100644 --- a/src/services/folder.service.ts +++ b/src/services/folder.service.ts @@ -1,8 +1,10 @@ import { CipherString } from '../models/domain/cipherString'; import { Folder } from '../models/domain/folder'; + import { FolderData } from '../models/data/folderData'; -import { FolderResponse } from '../models/response/folderResponse'; + import { FolderRequest } from '../models/request/folderRequest'; +import { FolderResponse } from '../models/response/folderResponse'; import ApiService from './api.service'; import ConstantsService from './constants.service'; @@ -11,14 +13,14 @@ import UserService from './user.service'; import UtilsService from './utils.service'; const Keys = { - foldersPrefix: 'folders_' + foldersPrefix: 'folders_', }; export default class FolderService { 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 { @@ -31,10 +33,10 @@ export default class FolderService { return folder; } - async get(id:string): Promise { + async get(id: string): Promise { const userId = await this.userService.getUserId(); const folders = await UtilsService.getObjFromStorage>(Keys.foldersPrefix + userId); - if(folders == null || !folders.has(id)) { + if (folders == null || !folders.has(id)) { return null; } @@ -44,7 +46,7 @@ export default class FolderService { async getAll(): Promise { const userId = await this.userService.getUserId(); const folders = await UtilsService.getObjFromStorage>(Keys.foldersPrefix + userId); - const response:Folder[] = []; + const response: Folder[] = []; folders.forEach((folder) => { response.push(new Folder(folder)); }); @@ -58,17 +60,17 @@ export default class FolderService { const decFolders: any[] = [{ id: null, - name: this.i18nService.noneFolder + name: this.i18nService.noneFolder, }]; const key = await this.cryptoService.getKey(); - if(key == null) { + if (key == null) { throw new Error('No key.'); } const promises = []; const folders = await this.getAll(); - for(const folder of folders) { + for (const folder of folders) { promises.push(folder.decrypt().then((f: any) => { decFolders.push(f); })); @@ -79,11 +81,11 @@ export default class FolderService { return this.decryptedFolderCache; } - async saveWithServer (folder: Folder): Promise { + async saveWithServer(folder: Folder): Promise { const request = new FolderRequest(folder); let response: FolderResponse; - if(folder.id == null) { + if (folder.id == null) { response = await this.apiService.postFolder(request); folder.id = response.id; } else { @@ -98,15 +100,15 @@ export default class FolderService { async upsert(folder: FolderData | FolderData[]): Promise { const userId = await this.userService.getUserId(); let folders = await UtilsService.getObjFromStorage>(Keys.foldersPrefix + userId); - if(folders == null) { + if (folders == null) { folders = new Map(); } - if(folder instanceof FolderData) { + if (folder instanceof FolderData) { const f = folder as FolderData; folders.set(f.id, f); } else { - for(const f of (folder as FolderData[])) { + for (const f of (folder as FolderData[])) { folders.set(f.id, f); } } @@ -115,29 +117,29 @@ export default class FolderService { this.decryptedFolderCache = null; } - async replace (folders: FolderData[]): Promise { + async replace(folders: FolderData[]): Promise { const userId = await this.userService.getUserId(); await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders); this.decryptedFolderCache = null; } async clear(userId: string): Promise { - await UtilsService.removeFromStorage(Keys.foldersPrefix + userId); + await UtilsService.removeFromStorage(Keys.foldersPrefix + userId); this.decryptedFolderCache = null; } async delete(id: string | string[]): Promise { const userId = await this.userService.getUserId(); - let folders = await UtilsService.getObjFromStorage>(Keys.foldersPrefix + userId); - if(folders == null) { + const folders = await UtilsService.getObjFromStorage>(Keys.foldersPrefix + userId); + if (folders == null) { return; } - if(id instanceof String) { + if (id instanceof String) { const i = id as string; folders.delete(i); } else { - for(const i of (id as string[])) { + for (const i of (id as string[])) { folders.delete(i); } }