1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-18 01:41:27 +01:00

import ts through node_modules alias

This commit is contained in:
Kyle Spearrin 2018-01-09 14:26:20 -05:00
parent e165b5cc70
commit f51bebd99a
49 changed files with 515 additions and 322 deletions

View File

@ -4,7 +4,7 @@ import MainBackground from './main.background';
import PasswordGenerationService from '../services/passwordGeneration.service'; import PasswordGenerationService from '../services/passwordGeneration.service';
import { Services } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/services/utils.service';
export default class CommandsBackground { export default class CommandsBackground {
private commands: any; private commands: any;
@ -35,7 +35,7 @@ export default class CommandsBackground {
private async generatePasswordToClipboard() { private async generatePasswordToClipboard() {
const options = await this.passwordGenerationService.getOptions(); const options = await this.passwordGenerationService.getOptions();
const password = PasswordGenerationService.generatePassword(options); const password = PasswordGenerationService.generatePassword(options);
Services.UtilsService.copyToClipboard(password); UtilsService.copyToClipboard(password);
this.passwordGenerationService.addHistory(password); this.passwordGenerationService.addHistory(password);
(window as any).ga('send', { (window as any).ga('send', {

View File

@ -5,7 +5,7 @@ import MainBackground from './main.background';
import CipherService from '../services/cipher.service'; import CipherService from '../services/cipher.service';
import PasswordGenerationService from '../services/passwordGeneration.service'; import PasswordGenerationService from '../services/passwordGeneration.service';
import { Services } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/services/utils.service';
export default class ContextMenusBackground { export default class ContextMenusBackground {
private contextMenus: any; private contextMenus: any;
@ -33,7 +33,7 @@ export default class ContextMenusBackground {
private async generatePasswordToClipboard() { private async generatePasswordToClipboard() {
const options = await this.passwordGenerationService.getOptions(); const options = await this.passwordGenerationService.getOptions();
const password = PasswordGenerationService.generatePassword(options); const password = PasswordGenerationService.generatePassword(options);
Services.UtilsService.copyToClipboard(password); UtilsService.copyToClipboard(password);
this.passwordGenerationService.addHistory(password); this.passwordGenerationService.addHistory(password);
(window as any).ga('send', { (window as any).ga('send', {
@ -69,13 +69,13 @@ export default class ContextMenusBackground {
hitType: 'event', hitType: 'event',
eventAction: 'Copied Username From Context Menu', eventAction: 'Copied Username From Context Menu',
}); });
Services.UtilsService.copyToClipboard(cipher.login.username); UtilsService.copyToClipboard(cipher.login.username);
} else if (info.parentMenuItemId === 'copy-password') { } else if (info.parentMenuItemId === 'copy-password') {
(window as any).ga('send', { (window as any).ga('send', {
hitType: 'event', hitType: 'event',
eventAction: 'Copied Password From Context Menu', eventAction: 'Copied Password From Context Menu',
}); });
Services.UtilsService.copyToClipboard(cipher.login.password); UtilsService.copyToClipboard(cipher.login.password);
} }
break; break;

View File

@ -2,13 +2,13 @@ import ConstantsService from '../services/constants.service';
import LockService from '../services/lock.service'; import LockService from '../services/lock.service';
import MainBackground from './main.background'; import MainBackground from './main.background';
import { Abstractions } from '@bitwarden/jslib'; import { StorageService } from 'jslib/abstractions';
export default class IdleBackground { export default class IdleBackground {
private idle: any; private idle: any;
constructor(private main: MainBackground, private lockService: LockService, constructor(private main: MainBackground, private lockService: LockService,
private storageService: Abstractions.StorageService) { private storageService: StorageService) {
this.idle = chrome.idle; this.idle = chrome.idle;
} }

View File

@ -1,4 +1,17 @@
import { Abstractions, Enums, Services } from '@bitwarden/jslib'; import { CipherType } from 'jslib/enums';
import {
CryptoService,
UtilsService,
} from 'jslib/services';
import {
CryptoService as CryptoServiceAbstraction,
MessagingService as MessagingServiceAbstraction,
PlatformUtilsService as PlatformUtilsServiceAbstraction,
StorageService as StorageServiceAbstraction,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
import BrowserApi from '../browser/browserApi'; import BrowserApi from '../browser/browserApi';
@ -32,13 +45,13 @@ import TotpService from '../services/totp.service';
import UserService from '../services/user.service'; import UserService from '../services/user.service';
export default class MainBackground { export default class MainBackground {
messagingService: Abstractions.MessagingService; messagingService: MessagingServiceAbstraction;
storageService: Abstractions.StorageService; storageService: StorageServiceAbstraction;
i18nService: any; i18nService: any;
platformUtilsService: Abstractions.PlatformUtilsService; platformUtilsService: PlatformUtilsServiceAbstraction;
utilsService: Abstractions.UtilsService; utilsService: UtilsServiceAbstraction;
constantsService: ConstantsService; constantsService: ConstantsService;
cryptoService: Abstractions.CryptoService; cryptoService: CryptoServiceAbstraction;
tokenService: TokenService; tokenService: TokenService;
appIdService: AppIdService; appIdService: AppIdService;
apiService: ApiService; apiService: ApiService;
@ -75,13 +88,13 @@ export default class MainBackground {
constructor() { constructor() {
// Services // Services
this.utilsService = new Services.UtilsService(); this.utilsService = new UtilsService();
this.platformUtilsService = new BrowserPlatformUtilsService(); this.platformUtilsService = new BrowserPlatformUtilsService();
this.messagingService = new BrowserMessagingService(this.platformUtilsService); this.messagingService = new BrowserMessagingService(this.platformUtilsService);
this.storageService = new BrowserStorageService(this.platformUtilsService); this.storageService = new BrowserStorageService(this.platformUtilsService);
this.i18nService = i18nService(this.platformUtilsService); this.i18nService = i18nService(this.platformUtilsService);
this.constantsService = new ConstantsService(this.i18nService, this.platformUtilsService); this.constantsService = new ConstantsService(this.i18nService, this.platformUtilsService);
this.cryptoService = new Services.CryptoService(this.storageService, this.cryptoService = new CryptoService(this.storageService,
this.storageService); this.storageService);
this.tokenService = new TokenService(this.storageService); this.tokenService = new TokenService(this.storageService);
this.appIdService = new AppIdService(this.storageService); this.appIdService = new AppIdService(this.storageService);
@ -346,7 +359,7 @@ export default class MainBackground {
} }
private async loadLoginContextMenuOptions(cipher: any) { private async loadLoginContextMenuOptions(cipher: any) {
if (cipher == null || cipher.type !== Enums.CipherType.Login) { if (cipher == null || cipher.type !== CipherType.Login) {
return; return;
} }
@ -363,7 +376,7 @@ export default class MainBackground {
private async loadContextMenuOptions(title: string, idSuffix: string, cipher: any) { private async loadContextMenuOptions(title: string, idSuffix: string, cipher: any) {
if (!chrome.contextMenus || this.menuOptionsLoaded.indexOf(idSuffix) > -1 || if (!chrome.contextMenus || this.menuOptionsLoaded.indexOf(idSuffix) > -1 ||
(cipher != null && cipher.type !== Enums.CipherType.Login)) { (cipher != null && cipher.type !== CipherType.Login)) {
return; return;
} }

View File

@ -1,4 +1,10 @@
import { Abstractions, Enums, Services } from '@bitwarden/jslib'; import { CipherType } from 'jslib/enums';
import { UtilsService } from 'jslib/services/utils.service';
import {
PlatformUtilsService,
} from 'jslib/abstractions';
import BrowserApi from '../browser/browserApi'; import BrowserApi from '../browser/browserApi';
@ -13,7 +19,7 @@ export default class RuntimeBackground {
private pageDetailsToAutoFill: any[] = []; private pageDetailsToAutoFill: any[] = [];
constructor(private main: MainBackground, private autofillService: AutofillService, constructor(private main: MainBackground, private autofillService: AutofillService,
private cipherService: CipherService, private platformUtilsService: Abstractions.PlatformUtilsService) { private cipherService: CipherService, private platformUtilsService: PlatformUtilsService) {
this.runtime = chrome.runtime; this.runtime = chrome.runtime;
} }
@ -146,7 +152,7 @@ export default class RuntimeBackground {
favorite: false, favorite: false,
name: loginInfo.name, name: loginInfo.name,
notes: null, notes: null,
type: Enums.CipherType.Login, type: CipherType.Login,
login: { login: {
uri: loginInfo.uri, uri: loginInfo.uri,
username: loginInfo.username, username: loginInfo.username,
@ -177,7 +183,7 @@ export default class RuntimeBackground {
} }
this.main.loginsToAdd.splice(i, 1); this.main.loginsToAdd.splice(i, 1);
const hostname = Services.UtilsService.getHostname(tab.url); const hostname = UtilsService.getHostname(tab.url);
await this.cipherService.saveNeverDomain(hostname); await this.cipherService.saveNeverDomain(hostname);
BrowserApi.tabSendMessage(tab, 'closeNotificationBar'); BrowserApi.tabSendMessage(tab, 'closeNotificationBar');
} }

View File

@ -1,13 +1,13 @@
import CipherService from '../services/cipher.service'; import CipherService from '../services/cipher.service';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
export default class WebRequestBackground { export default class WebRequestBackground {
private pendingAuthRequests: any[] = []; private pendingAuthRequests: any[] = [];
private webRequest: any; private webRequest: any;
private isFirefox: boolean; private isFirefox: boolean;
constructor(private platformUtilsService: Abstractions.PlatformUtilsService, constructor(private platformUtilsService: PlatformUtilsService,
private cipherService: CipherService) { private cipherService: CipherService) {
this.webRequest = (window as any).chrome.webRequest; this.webRequest = (window as any).chrome.webRequest;
this.isFirefox = platformUtilsService.isFirefox(); this.isFirefox = platformUtilsService.isFirefox();

View File

@ -30,7 +30,19 @@ import GlobalModule from './global/global.module';
import SettingsModule from './settings/settings.module'; import SettingsModule from './settings/settings.module';
// Model imports // Model imports
import { Data, Domain, Request, Response } from '@bitwarden/jslib'; import { Attachment } from '../../../node_modules/@bitwarden/jslib/src/models/domain/attachment';
import { Card } from '../../../node_modules/@bitwarden/jslib/src/models/domain/card';
import { Cipher } from '../../../node_modules/@bitwarden/jslib/src/models/domain/cipher';
import { CipherString } from '../../../node_modules/@bitwarden/jslib/src/models/domain/cipherString';
import { Field } from '../../../node_modules/@bitwarden/jslib/src/models/domain/field';
import { Folder } from '../../../node_modules/@bitwarden/jslib/src/models/domain/folder';
import { Identity } from '../../../node_modules/@bitwarden/jslib/src/models/domain/identity';
import { Login } from '../../../node_modules/@bitwarden/jslib/src/models/domain/login';
import { SecureNote } from '../../../node_modules/@bitwarden/jslib/src/models/domain/secureNote';
import * as Data from '../../../node_modules/@bitwarden/jslib/src/models/data';
import * as Request from '../../../node_modules/@bitwarden/jslib/src/models/request';
import * as Response from '../../../node_modules/@bitwarden/jslib/src/models/response';
angular angular
.module('bit', [ .module('bit', [

View File

@ -1,6 +1,6 @@
import * as template from './action-buttons.component.html'; import * as template from './action-buttons.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class ActionButtonsController implements ng.IController { export class ActionButtonsController implements ng.IController {
onView: Function; onView: Function;
@ -12,7 +12,7 @@ export class ActionButtonsController implements ng.IController {
constructor(private i18nService: any, private $analytics: any, private constantsService: any, private toastr: any, constructor(private i18nService: any, private $analytics: any, private constantsService: any, private toastr: any,
private $timeout: any, private $window: any, private $timeout: any, private $window: any,
private platformUtilsService: Abstractions.PlatformUtilsService) { private platformUtilsService: PlatformUtilsService) {
this.i18n = i18nService; this.i18n = i18nService;
this.constants = constantsService; this.constants = constantsService;
} }

View File

@ -1,12 +1,12 @@
import * as template from './pop-out.component.html'; import * as template from './pop-out.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class PopOutController implements ng.IController { export class PopOutController implements ng.IController {
i18n: any; i18n: any;
constructor(private $analytics: any, private $window: any, constructor(private $analytics: any, private $window: any,
private platformUtilsService: Abstractions.PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private i18nService: any) { private i18nService: any) {
this.i18n = i18nService; this.i18n = i18nService;
} }

View File

@ -1,4 +1,7 @@
import { Abstractions, Enums } from '@bitwarden/jslib'; import { CipherType } from 'jslib/enums/cipherType';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { UtilsService } from 'jslib/abstractions/utils.service';
import * as template from './current.component.html'; import * as template from './current.component.html';
@ -17,8 +20,8 @@ export class CurrentController {
disableSearch: boolean = false; disableSearch: boolean = false;
constructor($scope: any, private cipherService: any, constructor($scope: any, private cipherService: any,
private platformUtilsService: Abstractions.PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private utilsService: Abstractions.UtilsService, private toastr: any, private $window: any, private $state: any, private utilsService: UtilsService, private toastr: any, private $window: any, private $state: any,
private $timeout: any, private autofillService: any, private $analytics: any, private i18nService: any, private $timeout: any, private autofillService: any, private $analytics: any, private i18nService: any,
private $filter: any) { private $filter: any) {
this.i18n = i18nService; this.i18n = i18nService;
@ -117,8 +120,8 @@ export class CurrentController {
}); });
const otherTypes = [ const otherTypes = [
Enums.CipherType.Card, CipherType.Card,
Enums.CipherType.Identity, CipherType.Identity,
]; ];
this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any[]) => { this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any[]) => {
@ -131,13 +134,13 @@ export class CurrentController {
sortedCiphers.forEach((cipher: any) => { sortedCiphers.forEach((cipher: any) => {
switch (cipher.type) { switch (cipher.type) {
case Enums.CipherType.Login: case CipherType.Login:
loginCiphers.push(cipher); loginCiphers.push(cipher);
break; break;
case Enums.CipherType.Card: case CipherType.Card:
cardCiphers.push(cipher); cardCiphers.push(cipher);
break; break;
case Enums.CipherType.Identity: case CipherType.Identity:
identityCiphers.push(cipher); identityCiphers.push(cipher);
break; break;
default: default:

View File

@ -1,4 +1,4 @@
import { Abstractions } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/abstractions/utils.service';
export class MainController implements ng.IController { export class MainController implements ng.IController {
smBody: boolean; smBody: boolean;
@ -6,7 +6,7 @@ export class MainController implements ng.IController {
animation: string; animation: string;
constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any, constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any,
i18nService: any, $analytics: any, utilsService: Abstractions.UtilsService, $window: any) { i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) {
this.animation = ''; this.animation = '';
this.xsBody = $window.screen.availHeight < 600; this.xsBody = $window.screen.availHeight < 600;
this.smBody = !this.xsBody && $window.screen.availHeight <= 800; this.smBody = !this.xsBody && $window.screen.availHeight <= 800;

View File

@ -1,16 +1,18 @@
import * as angular from 'angular'; import * as angular from 'angular';
import * as template from './lock.component.html'; import * as template from './lock.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { CryptoService } from 'jslib/abstractions/crypto.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class LockController { export class LockController {
i18n: any; i18n: any;
masterPassword: string; masterPassword: string;
constructor(public $state: any, public i18nService: any, private $timeout: any, constructor(public $state: any, public i18nService: any, private $timeout: any,
private platformUtilsService: Abstractions.PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
public cryptoService: Abstractions.CryptoService, public toastr: any, public userService: any, public cryptoService: CryptoService, public toastr: any, public userService: any,
public messagingService: Abstractions.MessagingService, public SweetAlert: any) { public messagingService: MessagingService, public SweetAlert: any) {
this.i18n = i18nService; this.i18n = i18nService;
} }

View File

@ -1,14 +1,19 @@
import { Abstractions, Request } from '@bitwarden/jslib'; import { DeviceRequest } from 'jslib/models/request/deviceRequest';
import { TokenRequest } from 'jslib/models/request/tokenRequest';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
class AuthService { class AuthService {
constructor(public cryptoService: Abstractions.CryptoService, public apiService: any, public userService: any, constructor(public cryptoService: CryptoService, public apiService: any, public userService: any,
public tokenService: any, public $rootScope: any, public appIdService: any, public tokenService: any, public $rootScope: any, public appIdService: any,
public platformUtilsService: Abstractions.PlatformUtilsService, public constantsService: any, public platformUtilsService: PlatformUtilsService, public constantsService: any,
public messagingService: Abstractions.MessagingService) { public messagingService: MessagingService) {
} }
async logIn(email: string, masterPassword: string, twoFactorProvider?: number, async logIn(email: string, masterPassword: string, twoFactorProvider?: number,
twoFactorToken?: string, remember?: boolean) { twoFactorToken?: string, remember?: boolean) {
email = email.toLowerCase(); email = email.toLowerCase();
const key = this.cryptoService.makeKey(masterPassword, email); const key = this.cryptoService.makeKey(masterPassword, email);
@ -16,18 +21,18 @@ class AuthService {
const storedTwoFactorToken = await this.tokenService.getTwoFactorToken(email); const storedTwoFactorToken = await this.tokenService.getTwoFactorToken(email);
const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key); const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key);
const deviceRequest = new Request.Device(appId, this.platformUtilsService); const deviceRequest = new DeviceRequest(appId, this.platformUtilsService);
let request: Request.Token; let request: TokenRequest;
if (twoFactorToken != null && twoFactorProvider != null) { if (twoFactorToken != null && twoFactorProvider != null) {
request = new Request.Token(email, hashedPassword, twoFactorProvider, twoFactorToken, remember, request = new TokenRequest(email, hashedPassword, twoFactorProvider, twoFactorToken, remember,
deviceRequest); deviceRequest);
} else if (storedTwoFactorToken) { } else if (storedTwoFactorToken) {
request = new Request.Token(email, hashedPassword, this.constantsService.twoFactorProvider.remember, request = new TokenRequest(email, hashedPassword, this.constantsService.twoFactorProvider.remember,
storedTwoFactorToken, false, deviceRequest); storedTwoFactorToken, false, deviceRequest);
} else { } else {
request = new Request.Token(email, hashedPassword, null, null, false, deviceRequest); request = new TokenRequest(email, hashedPassword, null, null, false, deviceRequest);
} }
const response = await this.apiService.postIdentityToken(request); const response = await this.apiService.postIdentityToken(request);

View File

@ -1,4 +1,7 @@
import { Abstractions } from '@bitwarden/jslib'; import { CryptoService } from 'jslib/abstractions/crypto.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import { UtilsService } from 'jslib/abstractions/utils.service';
function getBackgroundService<T>(service: string) { function getBackgroundService<T>(service: string) {
return (): T => { return (): T => {
@ -7,18 +10,18 @@ function getBackgroundService<T>(service: string) {
}; };
} }
export const storageService = getBackgroundService<Abstractions.StorageService>('storageService'); export const storageService = getBackgroundService<StorageService>('storageService');
export const tokenService = getBackgroundService<any>('tokenService'); export const tokenService = getBackgroundService<any>('tokenService');
export const cryptoService = getBackgroundService<any>('cryptoService'); export const cryptoService = getBackgroundService<any>('cryptoService');
export const userService = getBackgroundService<any>('userService'); export const userService = getBackgroundService<any>('userService');
export const apiService = getBackgroundService<any>('apiService'); export const apiService = getBackgroundService<any>('apiService');
export const folderService = getBackgroundService<any>('folderService'); export const folderService = getBackgroundService<any>('folderService');
export const cipherService = getBackgroundService<Abstractions.CryptoService>('cipherService'); export const cipherService = getBackgroundService<CryptoService>('cipherService');
export const syncService = getBackgroundService<any>('syncService'); export const syncService = getBackgroundService<any>('syncService');
export const autofillService = getBackgroundService<any>('autofillService'); export const autofillService = getBackgroundService<any>('autofillService');
export const passwordGenerationService = getBackgroundService<any>('passwordGenerationService'); export const passwordGenerationService = getBackgroundService<any>('passwordGenerationService');
export const platformUtilsService = getBackgroundService<Abstractions.PlatformUtilsService>('platformUtilsService'); export const platformUtilsService = getBackgroundService<PlatformUtilsService>('platformUtilsService');
export const utilsService = getBackgroundService<Abstractions.UtilsService>('utilsService'); export const utilsService = getBackgroundService<UtilsService>('utilsService');
export const appIdService = getBackgroundService<any>('appIdService'); export const appIdService = getBackgroundService<any>('appIdService');
export const i18nService = getBackgroundService<any>('i18nService'); export const i18nService = getBackgroundService<any>('i18nService');
export const constantsService = getBackgroundService<any>('constantsService'); export const constantsService = getBackgroundService<any>('constantsService');

View File

@ -1,9 +1,9 @@
import { Abstractions } from '@bitwarden/jslib'; import { StorageService } from 'jslib/abstractions/storage.service';
class StateService { class StateService {
private state: any = {}; private state: any = {};
constructor(private storageService: Abstractions.StorageService, private constantsService: any) { constructor(private storageService: StorageService, private constantsService: any) {
} }
async init() { async init() {

View File

@ -1,7 +1,7 @@
import * as angular from 'angular'; import * as angular from 'angular';
import * as template from './environment.component.html'; import * as template from './environment.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class EnvironmentController { export class EnvironmentController {
iconsUrl: string; iconsUrl: string;
@ -12,7 +12,7 @@ export class EnvironmentController {
i18n: any; i18n: any;
constructor(private i18nService: any, private $analytics: any, constructor(private i18nService: any, private $analytics: any,
platformUtilsService: Abstractions.PlatformUtilsService, platformUtilsService: PlatformUtilsService,
private environmentService: any, private toastr: any, private $timeout: ng.ITimeoutService) { private environmentService: any, private toastr: any, private $timeout: ng.ITimeoutService) {
this.i18n = i18nService; this.i18n = i18nService;

View File

@ -1,7 +1,9 @@
import * as angular from 'angular'; import * as angular from 'angular';
import * as template from './add-folder.component.html'; import * as template from './add-folder.component.html';
import { Abstractions, Domain } from '@bitwarden/jslib'; import { Folder } from 'jslib/models/domain/';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class AddFolderController { export class AddFolderController {
savePromise: any; savePromise: any;
@ -9,7 +11,7 @@ export class AddFolderController {
i18n: any; i18n: any;
constructor(private folderService: any, private $state: any, private toastr: any, constructor(private folderService: any, private $state: any, private toastr: any,
platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, private i18nService: any, platformUtilsService: PlatformUtilsService, private $analytics: any, private i18nService: any,
$timeout: any) { $timeout: any) {
$timeout(() => { $timeout(() => {
platformUtilsService.initListSectionItemListeners(document, angular); platformUtilsService.initListSectionItemListeners(document, angular);
@ -28,7 +30,7 @@ export class AddFolderController {
} }
this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => { this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => {
const folder = new Domain.Folder(folderModel, true); const folder = new Folder(folderModel, true);
return this.folderService.saveWithServer(folder); return this.folderService.saveWithServer(folder);
}).then((folder: any) => { }).then((folder: any) => {
this.$analytics.eventTrack('Added Folder'); this.$analytics.eventTrack('Added Folder');

View File

@ -1,17 +1,19 @@
import * as angular from 'angular'; import * as angular from 'angular';
import * as template from './edit-folder.component.html'; import * as template from './edit-folder.component.html';
import { Abstractions, Domain } from '@bitwarden/jslib'; import { Folder } from 'jslib/models/domain/';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
export class EditFolderController { export class EditFolderController {
$transition$: any; $transition$: any;
folderId: any; folderId: any;
savePromise: any = null; savePromise: any = null;
i18n: any; i18n: any;
folder: Domain.Folder; folder: Folder;
constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any, constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any,
private SweetAlert: any, platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, private SweetAlert: any, platformUtilsService: PlatformUtilsService, private $analytics: any,
private i18nService: any, $timeout: any) { private i18nService: any, $timeout: any) {
this.i18n = i18nService; this.i18n = i18nService;
@ -27,7 +29,7 @@ export class EditFolderController {
this.folderId = this.$transition$.params('to').folderId; this.folderId = this.$transition$.params('to').folderId;
this.folderService.get(this.folderId).then((folder: any) => { this.folderService.get(this.folderId).then((folder: any) => {
return folder.decrypt(); return folder.decrypt();
}).then((model: Domain.Folder) => { }).then((model: Folder) => {
this.folder = model; this.folder = model;
}); });
} }
@ -39,7 +41,7 @@ export class EditFolderController {
} }
this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => { this.savePromise = this.folderService.encrypt(model).then((folderModel: any) => {
const folder = new Domain.Folder(folderModel, true); const folder = new Folder(folderModel, true);
return this.folderService.saveWithServer(folder); return this.folderService.saveWithServer(folder);
}).then((folder: any) => { }).then((folder: any) => {
this.$analytics.eventTrack('Edited Folder'); this.$analytics.eventTrack('Edited Folder');

View File

@ -1,9 +1,9 @@
import * as template from './folders.component.html'; import * as template from './folders.component.html';
import { Domain } from '@bitwarden/jslib'; import { Folder } from 'jslib/models/domain';
export class FoldersController { export class FoldersController {
folders: Domain.Folder[] = []; folders: Folder[] = [];
i18n: any; i18n: any;
loaded = false; loaded = false;

View File

@ -1,6 +1,8 @@
import * as angular from 'angular'; import * as angular from 'angular';
import { Abstractions } from '@bitwarden/jslib'; import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import StateService from '../services/state.service'; import StateService from '../services/state.service';
import * as template from './options.component.html'; import * as template from './options.component.html';
@ -15,9 +17,9 @@ export class OptionsController {
i18n: any; i18n: any;
constructor(private i18nService: any, private $analytics: any, private constantsService: any, constructor(private i18nService: any, private $analytics: any, private constantsService: any,
private platformUtilsService: Abstractions.PlatformUtilsService, private totpService: any, private platformUtilsService: PlatformUtilsService, private totpService: any,
private stateService: StateService, private storageService: Abstractions.StorageService, private stateService: StateService, private storageService: StorageService,
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) { public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
this.i18n = i18nService; this.i18n = i18nService;
$timeout(() => { $timeout(() => {

View File

@ -1,23 +1,28 @@
import * as angular from 'angular'; import * as angular from 'angular';
import { Abstractions, Enums } from '@bitwarden/jslib'; import { DeviceType } from 'jslib/enums/deviceType';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { StorageService } from 'jslib/abstractions/storage.service';
import ConstantsService from '../../../services/constants.service'; import ConstantsService from '../../../services/constants.service';
import * as template from './settings.component.html'; import * as template from './settings.component.html';
const RateUrls = { const RateUrls = {
[Enums.DeviceType.Chrome]: [DeviceType.Chrome]:
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews', 'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
[Enums.DeviceType.Firefox]: [DeviceType.Firefox]:
'https://addons.mozilla.org/en-US/firefox/addon/bitwarden-password-manager/#reviews', 'https://addons.mozilla.org/en-US/firefox/addon/bitwarden-password-manager/#reviews',
[Enums.DeviceType.Opera]: [DeviceType.Opera]:
'https://addons.opera.com/en/extensions/details/bitwarden-free-password-manager/#feedback-container', 'https://addons.opera.com/en/extensions/details/bitwarden-free-password-manager/#feedback-container',
[Enums.DeviceType.Edge]: [DeviceType.Edge]:
'https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl', 'https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl',
[Enums.DeviceType.Vivaldi]: [DeviceType.Vivaldi]:
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews', 'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
[Enums.DeviceType.Safari]: [DeviceType.Safari]:
'https://itunes.com', // TODO 'https://itunes.com', // TODO
}; };
@ -27,11 +32,11 @@ export class SettingsController {
showOnLocked: boolean; showOnLocked: boolean;
constructor(private $state: any, private SweetAlert: any, constructor(private $state: any, private SweetAlert: any,
private platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, private platformUtilsService: PlatformUtilsService, private $analytics: any,
private i18nService: any, private constantsService: ConstantsService, private i18nService: any, private constantsService: ConstantsService,
private cryptoService: Abstractions.CryptoService, private lockService: any, private cryptoService: CryptoService, private lockService: any,
private storageService: Abstractions.StorageService, private storageService: StorageService,
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) { public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
this.i18n = i18nService; this.i18n = i18nService;
$timeout(() => { $timeout(() => {

View File

@ -2,14 +2,17 @@ import * as angular from 'angular';
import * as papa from 'papaparse'; import * as papa from 'papaparse';
import * as template from './export.component.html'; import * as template from './export.component.html';
import { Abstractions, Enums } from '@bitwarden/jslib'; import { CipherType } from 'jslib/enums/cipherType';
import { CryptoService } from 'jslib/abstractions/crypto.service';
import { UtilsService } from 'jslib/abstractions/utils.service';
export class ExportController { export class ExportController {
i18n: any; i18n: any;
masterPassword: string; masterPassword: string;
constructor(private $state: any, private cryptoService: Abstractions.CryptoService, constructor(private $state: any, private cryptoService: CryptoService,
private toastr: any, private utilsService: Abstractions.UtilsService, private $analytics: any, private toastr: any, private utilsService: UtilsService, private $analytics: any,
private i18nService: any, private folderService: any, private cipherService: any, private i18nService: any, private folderService: any, private cipherService: any,
private $window: any, private userService: any) { private $window: any, private userService: any) {
this.i18n = i18nService; this.i18n = i18nService;
@ -72,7 +75,7 @@ export class ExportController {
const exportCiphers = []; const exportCiphers = [];
for (const c of decCiphers) { for (const c of decCiphers) {
// only export logins and secure notes // only export logins and secure notes
if (c.type !== Enums.CipherType.Login && c.type !== Enums.CipherType.SecureNote) { if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) {
continue; continue;
} }
@ -103,14 +106,14 @@ export class ExportController {
} }
switch (c.type) { switch (c.type) {
case Enums.CipherType.Login: case CipherType.Login:
cipher.type = 'login'; cipher.type = 'login';
cipher.login_uri = c.login.uri; cipher.login_uri = c.login.uri;
cipher.login_username = c.login.username; cipher.login_username = c.login.username;
cipher.login_password = c.login.password; cipher.login_password = c.login.password;
cipher.login_totp = c.login.totp; cipher.login_totp = c.login.totp;
break; break;
case Enums.CipherType.SecureNote: case CipherType.SecureNote:
cipher.type = 'note'; cipher.type = 'note';
break; break;
default: default:

View File

@ -1,10 +1,10 @@
import * as template from './password-generator-history.component.html'; import * as template from './password-generator-history.component.html';
import { Domain } from '@bitwarden/jslib'; import { PasswordHistory } from 'jslib/models/domain/passwordHistory';
export class PasswordGeneratorHistoryController { export class PasswordGeneratorHistoryController {
$transition$: any; $transition$: any;
history: Domain.PasswordHistory[]; history: PasswordHistory[];
editState: any; editState: any;
addState: any; addState: any;
i18n: any; i18n: any;

View File

@ -1,7 +1,7 @@
import * as angular from 'angular'; import * as angular from 'angular';
import * as template from './password-generator.component.html'; import * as template from './password-generator.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
export class PasswordGeneratorController { export class PasswordGeneratorController {
$transition$: any; $transition$: any;
@ -13,7 +13,7 @@ export class PasswordGeneratorController {
i18n: any; i18n: any;
constructor(private $state: any, private passwordGenerationService: any, constructor(private $state: any, private passwordGenerationService: any,
private toastr: any, private platformUtilsService: Abstractions.PlatformUtilsService, private toastr: any, private platformUtilsService: PlatformUtilsService,
private $analytics: any, private i18nService: any, private $timeout: any) { private $analytics: any, private i18nService: any, private $timeout: any) {
this.i18n = i18nService; this.i18n = i18nService;

View File

@ -1,6 +1,6 @@
import * as template from './tools.component.html'; import * as template from './tools.component.html';
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
export class ToolsController { export class ToolsController {
showExport: boolean; showExport: boolean;
@ -8,7 +8,7 @@ export class ToolsController {
private webVaultBaseUrl: string = 'https://vault.bitwarden.com'; private webVaultBaseUrl: string = 'https://vault.bitwarden.com';
constructor(private SweetAlert: any, private i18nService: any, constructor(private SweetAlert: any, private i18nService: any,
private $analytics: any, private platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, private platformUtilsService: PlatformUtilsService,
private environmentService: any) { private environmentService: any) {
this.i18n = i18nService; this.i18n = i18nService;
this.showExport = !platformUtilsService.isEdge(); this.showExport = !platformUtilsService.isEdge();

View File

@ -2,7 +2,36 @@ import AppIdService from './appId.service';
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
import TokenService from './token.service'; import TokenService from './token.service';
import { Abstractions, Domain, Request as Req, Response as Res } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
import { EnvironmentUrls } from 'jslib/models/domain';
import {
CipherRequest,
DeviceRequest,
DeviceTokenRequest,
FolderRequest,
PasswordHintRequest,
RegisterRequest,
TokenRequest,
TwoFactorEmailRequest,
} from 'jslib/models/request';
import {
AttachmentResponse,
CipherResponse,
DeviceResponse,
DomainsResponse,
ErrorResponse,
FolderResponse,
GlobalDomainResponse,
IdentityTokenResponse,
KeysResponse,
ListResponse,
ProfileOrganizationResponse,
ProfileResponse,
SyncResponse,
} from 'jslib/models/response';
export default class ApiService { export default class ApiService {
urlsSet: boolean = false; urlsSet: boolean = false;
@ -11,13 +40,13 @@ export default class ApiService {
deviceType: string; deviceType: string;
logoutCallback: Function; logoutCallback: Function;
constructor(private tokenService: TokenService, platformUtilsService: Abstractions.PlatformUtilsService, constructor(private tokenService: TokenService, platformUtilsService: PlatformUtilsService,
logoutCallback: Function) { logoutCallback: Function) {
this.logoutCallback = logoutCallback; this.logoutCallback = logoutCallback;
this.deviceType = platformUtilsService.getDevice().toString(); this.deviceType = platformUtilsService.getDevice().toString();
} }
setUrls(urls: Domain.EnvironmentUrls) { setUrls(urls: EnvironmentUrls) {
this.urlsSet = true; this.urlsSet = true;
if (urls.base != null) { if (urls.base != null) {
@ -57,7 +86,7 @@ export default class ApiService {
// Auth APIs // Auth APIs
async postIdentityToken(request: Req.Token): Promise<Res.IdentityToken | any> { async postIdentityToken(request: TokenRequest): Promise<IdentityTokenResponse | any> {
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',
@ -77,7 +106,7 @@ export default class ApiService {
if (responseJson != null) { if (responseJson != null) {
if (response.status === 200) { if (response.status === 200) {
return new Res.IdentityToken(responseJson); return new IdentityTokenResponse(responseJson);
} else if (response.status === 400 && responseJson.TwoFactorProviders2 && } else if (response.status === 400 && responseJson.TwoFactorProviders2 &&
Object.keys(responseJson.TwoFactorProviders2).length) { Object.keys(responseJson.TwoFactorProviders2).length) {
await this.tokenService.clearTwoFactorToken(request.email); await this.tokenService.clearTwoFactorToken(request.email);
@ -85,7 +114,7 @@ export default class ApiService {
} }
} }
return Promise.reject(new Res.Error(responseJson, response.status, true)); return Promise.reject(new ErrorResponse(responseJson, response.status, true));
} }
async refreshIdentityToken(): Promise<any> { async refreshIdentityToken(): Promise<any> {
@ -98,7 +127,7 @@ export default class ApiService {
// Two Factor APIs // Two Factor APIs
async postTwoFactorEmail(request: Req.TwoFactorEmail): Promise<any> { async postTwoFactorEmail(request: TwoFactorEmailRequest): Promise<any> {
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',
@ -136,7 +165,7 @@ export default class ApiService {
} }
} }
async postPasswordHint(request: Req.PasswordHint): Promise<any> { async postPasswordHint(request: PasswordHintRequest): Promise<any> {
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',
@ -153,7 +182,7 @@ export default class ApiService {
} }
} }
async postRegister(request: Req.Register): Promise<any> { async postRegister(request: RegisterRequest): Promise<any> {
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',
@ -172,7 +201,7 @@ export default class ApiService {
// Folder APIs // Folder APIs
async postFolder(request: Req.Folder): Promise<Res.Folder> { async postFolder(request: FolderRequest): Promise<FolderResponse> {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
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),
@ -188,14 +217,14 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Folder(responseJson); return new FolderResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
} }
} }
async putFolder(id: string, request: Req.Folder): Promise<Res.Folder> { async putFolder(id: string, request: FolderRequest): Promise<FolderResponse> {
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, {
body: JSON.stringify(request), body: JSON.stringify(request),
@ -211,7 +240,7 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Folder(responseJson); return new FolderResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
@ -237,7 +266,7 @@ export default class ApiService {
// Cipher APIs // Cipher APIs
async postCipher(request: Req.Cipher): Promise<Res.Cipher> { async postCipher(request: CipherRequest): Promise<CipherResponse> {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
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),
@ -253,14 +282,14 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Cipher(responseJson); return new CipherResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
} }
} }
async putCipher(id: string, request: Req.Cipher): Promise<Res.Cipher> { async putCipher(id: string, request: CipherRequest): Promise<CipherResponse> {
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, {
body: JSON.stringify(request), body: JSON.stringify(request),
@ -276,7 +305,7 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Cipher(responseJson); return new CipherResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
@ -302,7 +331,7 @@ export default class ApiService {
// Attachments APIs // Attachments APIs
async postCipherAttachment(id: string, data: FormData): Promise<Res.Cipher> { async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {
const authHeader = await this.handleTokenState(); const authHeader = await this.handleTokenState();
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,
@ -317,7 +346,7 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Cipher(responseJson); return new CipherResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
@ -343,7 +372,7 @@ export default class ApiService {
// Sync APIs // Sync APIs
async getSync(): Promise<Res.Sync> { async getSync(): Promise<SyncResponse> {
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',
@ -356,7 +385,7 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
return new Res.Sync(responseJson); return new SyncResponse(responseJson);
} else { } else {
const error = await this.handleError(response, false); const error = await this.handleError(response, false);
return Promise.reject(error); return Promise.reject(error);
@ -365,7 +394,7 @@ export default class ApiService {
// Helpers // Helpers
private async handleError(response: Response, tokenError: boolean): Promise<Res.Error> { private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {
if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) { if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) {
this.logoutCallback(true); this.logoutCallback(true);
return null; return null;
@ -377,7 +406,7 @@ export default class ApiService {
responseJson = await response.json(); responseJson = await response.json();
} }
return new Res.Error(responseJson, response.status, tokenError); return new ErrorResponse(responseJson, response.status, tokenError);
} }
private async handleTokenState(): Promise<string> { private async handleTokenState(): Promise<string> {
@ -392,7 +421,7 @@ export default class ApiService {
return 'Bearer ' + accessToken; return 'Bearer ' + accessToken;
} }
private async doRefreshToken(): Promise<Res.IdentityToken> { private async doRefreshToken(): Promise<IdentityTokenResponse> {
const refreshToken = await this.tokenService.getRefreshToken(); const refreshToken = await this.tokenService.getRefreshToken();
if (refreshToken == null || refreshToken === '') { if (refreshToken == null || refreshToken === '') {
throw new Error(); throw new Error();
@ -415,7 +444,7 @@ export default class ApiService {
if (response.status === 200) { if (response.status === 200) {
const responseJson = await response.json(); const responseJson = await response.json();
const tokenResponse = new Res.IdentityToken(responseJson); const tokenResponse = new IdentityTokenResponse(responseJson);
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken); await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
return tokenResponse; return tokenResponse;
} else { } else {

View File

@ -1,7 +1,9 @@
import { Abstractions, Services } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/services';
import { StorageService } from 'jslib/abstractions';
export default class AppIdService { export default class AppIdService {
constructor(private storageService: Abstractions.StorageService) { constructor(private storageService: StorageService) {
} }
getAppId(): Promise<string> { getAppId(): Promise<string> {
@ -18,7 +20,7 @@ export default class AppIdService {
return existingId; return existingId;
} }
const guid = Services.UtilsService.newGuid(); const guid = UtilsService.newGuid();
await this.storageService.save(key, guid); await this.storageService.save(key, guid);
return guid; return guid;
} }

View File

@ -1,4 +1,7 @@
import { Abstractions, Enums, Services } from '@bitwarden/jslib'; import {
CipherType,
FieldType,
} from 'jslib/enums';
import AutofillField from '../models/domain/autofillField'; import AutofillField from '../models/domain/autofillField';
import AutofillPageDetails from '../models/domain/autofillPageDetails'; import AutofillPageDetails from '../models/domain/autofillPageDetails';
@ -8,6 +11,13 @@ import CipherService from './cipher.service';
import TokenService from './token.service'; import TokenService from './token.service';
import TotpService from './totp.service'; import TotpService from './totp.service';
import { UtilsService } from 'jslib/services';
import {
PlatformUtilsService,
UtilsService as UtilsServiceAbstraction,
} from 'jslib/abstractions';
const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag', const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',
'placeholder', 'label-left', 'label-top']; 'placeholder', 'label-left', 'label-top'];
@ -90,8 +100,8 @@ var IsoProvinces: { [id: string]: string; } = {
export default class AutofillService { export default class AutofillService {
constructor(public cipherService: CipherService, public tokenService: TokenService, constructor(public cipherService: CipherService, public tokenService: TokenService,
public totpService: TotpService, public utilsService: Services.UtilsService, public totpService: TotpService, public utilsService: UtilsServiceAbstraction,
public platformUtilsService: Abstractions.PlatformUtilsService) { public platformUtilsService: PlatformUtilsService) {
} }
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
@ -165,7 +175,7 @@ export default class AutofillService {
fillScript: fillScript, fillScript: fillScript,
}, { frameId: pd.frameId }); }, { frameId: pd.frameId });
if (options.cipher.type !== Enums.CipherType.Login || totpPromise || if (options.cipher.type !== CipherType.Login || totpPromise ||
(options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp || (options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp ||
!options.cipher.login.totp || !this.tokenService.getPremium()) { !options.cipher.login.totp || !this.tokenService.getPremium()) {
return; return;
@ -179,7 +189,7 @@ export default class AutofillService {
return null; return null;
}).then((code: string) => { }).then((code: string) => {
if (code) { if (code) {
Services.UtilsService.copyToClipboard(code); UtilsService.copyToClipboard(code);
} }
return code; return code;
@ -267,7 +277,7 @@ export default class AutofillService {
const matchingIndex = this.findMatchingFieldIndex(field, fieldNames); const matchingIndex = this.findMatchingFieldIndex(field, fieldNames);
if (matchingIndex > -1) { if (matchingIndex > -1) {
let val = fields[matchingIndex].value; let val = fields[matchingIndex].value;
if (val == null && fields[matchingIndex].type === Enums.FieldType.Boolean) { if (val == null && fields[matchingIndex].type === FieldType.Boolean) {
val = 'false'; val = 'false';
} }
@ -279,13 +289,13 @@ export default class AutofillService {
} }
switch (options.cipher.type) { switch (options.cipher.type) {
case Enums.CipherType.Login: case CipherType.Login:
fillScript = this.generateLoginFillScript(fillScript, pageDetails, filledFields, options); fillScript = this.generateLoginFillScript(fillScript, pageDetails, filledFields, options);
break; break;
case Enums.CipherType.Card: case CipherType.Card:
fillScript = this.generateCardFillScript(fillScript, pageDetails, filledFields, options); fillScript = this.generateCardFillScript(fillScript, pageDetails, filledFields, options);
break; break;
case Enums.CipherType.Identity: case CipherType.Identity:
fillScript = this.generateIdentityFillScript(fillScript, pageDetails, filledFields, options); fillScript = this.generateIdentityFillScript(fillScript, pageDetails, filledFields, options);
break; break;
default: default:

View File

@ -1,7 +1,10 @@
import { Abstractions } from '@bitwarden/jslib'; import {
MessagingService,
PlatformUtilsService,
} from 'jslib/abstractions';
export default class BrowserMessagingService implements Abstractions.MessagingService { export default class BrowserMessagingService implements MessagingService {
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) { constructor(private platformUtilsService: PlatformUtilsService) {
} }
send(subscriber: string, arg: any = {}) { send(subscriber: string, arg: any = {}) {

View File

@ -1,5 +1,6 @@
import BrowserPlatformUtilsService from './browserPlatformUtils.service'; import BrowserPlatformUtilsService from './browserPlatformUtils.service';
import { Enums } from '@bitwarden/jslib';
import { DeviceType } from 'jslib/enums';
describe('Browser Utils Service', () => { describe('Browser Utils Service', () => {
describe('getDomain', () => { describe('getDomain', () => {
@ -48,7 +49,7 @@ describe('Browser Utils Service', () => {
}); });
const browserPlatformUtilsService = new BrowserPlatformUtilsService(); const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Chrome); expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Chrome);
}); });
it('should detect firefox', () => { it('should detect firefox', () => {
@ -58,7 +59,7 @@ describe('Browser Utils Service', () => {
}); });
const browserPlatformUtilsService = new BrowserPlatformUtilsService(); const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Firefox); expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Firefox);
}); });
it('should detect opera', () => { it('should detect opera', () => {
@ -68,7 +69,7 @@ describe('Browser Utils Service', () => {
}); });
const browserPlatformUtilsService = new BrowserPlatformUtilsService(); const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Opera); expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Opera);
}); });
it('should detect edge', () => { it('should detect edge', () => {
@ -78,7 +79,7 @@ describe('Browser Utils Service', () => {
}); });
const browserPlatformUtilsService = new BrowserPlatformUtilsService(); const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Edge); expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Edge);
}); });
}); });
}); });

View File

@ -1,17 +1,19 @@
import * as tldjs from 'tldjs'; import * as tldjs from 'tldjs';
import { Abstractions, Enums } from '@bitwarden/jslib'; import { DeviceType } from 'jslib/enums';
import { PlatformUtilsService } from 'jslib/abstractions';
const AnalyticsIds = { const AnalyticsIds = {
[Enums.DeviceType.Chrome]: 'UA-81915606-6', [DeviceType.Chrome]: 'UA-81915606-6',
[Enums.DeviceType.Firefox]: 'UA-81915606-7', [DeviceType.Firefox]: 'UA-81915606-7',
[Enums.DeviceType.Opera]: 'UA-81915606-8', [DeviceType.Opera]: 'UA-81915606-8',
[Enums.DeviceType.Edge]: 'UA-81915606-9', [DeviceType.Edge]: 'UA-81915606-9',
[Enums.DeviceType.Vivaldi]: 'UA-81915606-15', [DeviceType.Vivaldi]: 'UA-81915606-15',
[Enums.DeviceType.Safari]: 'UA-81915606-16', [DeviceType.Safari]: 'UA-81915606-16',
}; };
export default class BrowserPlatformUtilsService implements Abstractions.PlatformUtilsService { export default class BrowserPlatformUtilsService implements PlatformUtilsService {
static getDomain(uriString: string): string { static getDomain(uriString: string): string {
if (uriString == null) { if (uriString == null) {
return null; return null;
@ -49,56 +51,56 @@ export default class BrowserPlatformUtilsService implements Abstractions.Platfor
return ipRegex.test(ipString); return ipRegex.test(ipString);
} }
private deviceCache: Enums.DeviceType = null; private deviceCache: DeviceType = null;
private analyticsIdCache: string = null; private analyticsIdCache: string = null;
getDevice(): Enums.DeviceType { getDevice(): DeviceType {
if (this.deviceCache) { if (this.deviceCache) {
return this.deviceCache; return this.deviceCache;
} }
if (navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1) { if (navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1) {
this.deviceCache = Enums.DeviceType.Firefox; this.deviceCache = DeviceType.Firefox;
} else if ((!!(window as any).opr && !!opr.addons) || !!(window as any).opera || } else if ((!!(window as any).opr && !!opr.addons) || !!(window as any).opera ||
navigator.userAgent.indexOf(' OPR/') >= 0) { navigator.userAgent.indexOf(' OPR/') >= 0) {
this.deviceCache = Enums.DeviceType.Opera; this.deviceCache = DeviceType.Opera;
} else if (navigator.userAgent.indexOf(' Edge/') !== -1) { } else if (navigator.userAgent.indexOf(' Edge/') !== -1) {
this.deviceCache = Enums.DeviceType.Edge; this.deviceCache = DeviceType.Edge;
} else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) { } else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) {
this.deviceCache = Enums.DeviceType.Vivaldi; this.deviceCache = DeviceType.Vivaldi;
} else if ((window as any).chrome) { } else if ((window as any).chrome) {
this.deviceCache = Enums.DeviceType.Chrome; this.deviceCache = DeviceType.Chrome;
} }
return this.deviceCache; return this.deviceCache;
} }
getDeviceString(): string { getDeviceString(): string {
return Enums.DeviceType[this.getDevice()].toLowerCase(); return DeviceType[this.getDevice()].toLowerCase();
} }
isFirefox(): boolean { isFirefox(): boolean {
return this.getDevice() === Enums.DeviceType.Firefox; return this.getDevice() === DeviceType.Firefox;
} }
isChrome(): boolean { isChrome(): boolean {
return this.getDevice() === Enums.DeviceType.Chrome; return this.getDevice() === DeviceType.Chrome;
} }
isEdge(): boolean { isEdge(): boolean {
return this.getDevice() === Enums.DeviceType.Edge; return this.getDevice() === DeviceType.Edge;
} }
isOpera(): boolean { isOpera(): boolean {
return this.getDevice() === Enums.DeviceType.Opera; return this.getDevice() === DeviceType.Opera;
} }
isVivaldi(): boolean { isVivaldi(): boolean {
return this.getDevice() === Enums.DeviceType.Vivaldi; return this.getDevice() === DeviceType.Vivaldi;
} }
isSafari(): boolean { isSafari(): boolean {
return this.getDevice() === Enums.DeviceType.Safari; return this.getDevice() === DeviceType.Safari;
} }
analyticsId(): string { analyticsId(): string {

View File

@ -1,7 +1,10 @@
import { Abstractions } from '@bitwarden/jslib'; import {
PlatformUtilsService,
StorageService,
} from 'jslib/abstractions';
export default class BrowserStorageService implements Abstractions.StorageService { export default class BrowserStorageService implements StorageService {
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) { constructor(private platformUtilsService: PlatformUtilsService) {
} }
get<T>(key: string): Promise<T> { get<T>(key: string): Promise<T> {

View File

@ -1,4 +1,25 @@
import { Abstractions, Data, Domain, Enums, Request, Response } from '@bitwarden/jslib'; import { CipherType } from 'jslib/enums';
import { CipherData } from 'jslib/models/data';
import {
Cipher,
CipherString,
Field,
SymmetricCryptoKey,
} from 'jslib/models/domain';
import { CipherRequest } from 'jslib/models/request';
import {
CipherResponse,
ErrorResponse,
} from 'jslib/models/response';
import {
CryptoService,
StorageService,
} from 'jslib/abstractions';
import ApiService from './api.service'; import ApiService from './api.service';
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
@ -54,17 +75,17 @@ export default class CipherService {
decryptedCipherCache: any[]; decryptedCipherCache: any[];
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService, constructor(private cryptoService: CryptoService, private userService: UserService,
private settingsService: SettingsService, private apiService: ApiService, private settingsService: SettingsService, private apiService: ApiService,
private storageService: Abstractions.StorageService) { private storageService: StorageService) {
} }
clearCache(): void { clearCache(): void {
this.decryptedCipherCache = null; this.decryptedCipherCache = null;
} }
async encrypt(model: any): Promise<Domain.Cipher> { async encrypt(model: any): Promise<Cipher> {
const cipher = new Domain.Cipher(); const cipher = new Cipher();
cipher.id = model.id; cipher.id = model.id;
cipher.folderId = model.folderId; cipher.folderId = model.folderId;
cipher.favorite = model.favorite; cipher.favorite = model.favorite;
@ -87,17 +108,17 @@ export default class CipherService {
return cipher; return cipher;
} }
async encryptFields(fieldsModel: any[], key: Domain.SymmetricCryptoKey): Promise<Domain.Field[]> { async encryptFields(fieldsModel: any[], key: SymmetricCryptoKey): Promise<Field[]> {
if (!fieldsModel || !fieldsModel.length) { if (!fieldsModel || !fieldsModel.length) {
return null; return null;
} }
const self = this; const self = this;
const encFields: Domain.Field[] = []; const encFields: Field[] = [];
await fieldsModel.reduce((promise, field) => { await fieldsModel.reduce((promise, field) => {
return promise.then(() => { return promise.then(() => {
return self.encryptField(field, key); return self.encryptField(field, key);
}).then((encField: Domain.Field) => { }).then((encField: Field) => {
encFields.push(encField); encFields.push(encField);
}); });
}, Promise.resolve()); }, Promise.resolve());
@ -105,8 +126,8 @@ export default class CipherService {
return encFields; return encFields;
} }
async encryptField(fieldModel: any, key: Domain.SymmetricCryptoKey): Promise<Domain.Field> { async encryptField(fieldModel: any, key: SymmetricCryptoKey): Promise<Field> {
const field = new Domain.Field(); const field = new Field();
field.type = fieldModel.type; field.type = fieldModel.type;
await this.encryptObjProperty(fieldModel, field, { await this.encryptObjProperty(fieldModel, field, {
@ -117,27 +138,27 @@ export default class CipherService {
return field; return field;
} }
async get(id: string): Promise<Domain.Cipher> { async get(id: string): Promise<Cipher> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const localData = await this.storageService.get<any>(Keys.localData); const localData = await this.storageService.get<any>(Keys.localData);
const ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>( const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId); Keys.ciphersPrefix + userId);
if (ciphers == null || !ciphers.hasOwnProperty(id)) { if (ciphers == null || !ciphers.hasOwnProperty(id)) {
return null; return null;
} }
return new Domain.Cipher(ciphers[id], false, localData ? localData[id] : null); return new Cipher(ciphers[id], false, localData ? localData[id] : null);
} }
async getAll(): Promise<Domain.Cipher[]> { async getAll(): Promise<Cipher[]> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const localData = await this.storageService.get<any>(Keys.localData); const localData = await this.storageService.get<any>(Keys.localData);
const ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>( const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId); Keys.ciphersPrefix + userId);
const response: Domain.Cipher[] = []; const response: Cipher[] = [];
for (const id in ciphers) { for (const id in ciphers) {
if (ciphers.hasOwnProperty(id)) { if (ciphers.hasOwnProperty(id)) {
response.push(new Domain.Cipher(ciphers[id], false, localData ? localData[id] : null)); response.push(new Cipher(ciphers[id], false, localData ? localData[id] : null));
} }
} }
return response; return response;
@ -209,7 +230,7 @@ export default class CipherService {
const ciphersToReturn: any[] = []; const ciphersToReturn: any[] = [];
ciphers.forEach((cipher) => { ciphers.forEach((cipher) => {
if (domain && cipher.type === Enums.CipherType.Login && cipher.login.domain && if (domain && cipher.type === CipherType.Login && cipher.login.domain &&
matchingDomains.indexOf(cipher.login.domain) > -1) { matchingDomains.indexOf(cipher.login.domain) > -1) {
ciphersToReturn.push(cipher); ciphersToReturn.push(cipher);
} else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) { } else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) {
@ -272,10 +293,10 @@ export default class CipherService {
await this.storageService.save(Keys.neverDomains, domains); await this.storageService.save(Keys.neverDomains, domains);
} }
async saveWithServer(cipher: Domain.Cipher): Promise<any> { async saveWithServer(cipher: Cipher): Promise<any> {
const request = new Request.Cipher(cipher); const request = new CipherRequest(cipher);
let response: Response.Cipher; let response: CipherResponse;
if (cipher.id == null) { if (cipher.id == null) {
response = await this.apiService.postCipher(request); response = await this.apiService.postCipher(request);
cipher.id = response.id; cipher.id = response.id;
@ -284,11 +305,11 @@ export default class CipherService {
} }
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const data = new Data.Cipher(response, userId, cipher.collectionIds); const data = new CipherData(response, userId, cipher.collectionIds);
await this.upsert(data); await this.upsert(data);
} }
saveAttachmentWithServer(cipher: Domain.Cipher, unencryptedFile: any): Promise<any> { saveAttachmentWithServer(cipher: Cipher, unencryptedFile: any): Promise<any> {
const self = this; const self = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -304,18 +325,18 @@ export default class CipherService {
const blob = new Blob([encData], { type: 'application/octet-stream' }); const blob = new Blob([encData], { type: 'application/octet-stream' });
fd.append('data', blob, encFileName.encryptedString); fd.append('data', blob, encFileName.encryptedString);
let response: Response.Cipher; let response: CipherResponse;
try { try {
response = await self.apiService.postCipherAttachment(cipher.id, fd); response = await self.apiService.postCipherAttachment(cipher.id, fd);
} catch (e) { } catch (e) {
reject((e as Response.Error).getSingleMessage()); reject((e as ErrorResponse).getSingleMessage());
return; return;
} }
const userId = await self.userService.getUserId(); const userId = await self.userService.getUserId();
const data = new Data.Cipher(response, userId, cipher.collectionIds); const data = new CipherData(response, userId, cipher.collectionIds);
this.upsert(data); this.upsert(data);
resolve(new Domain.Cipher(data)); resolve(new Cipher(data));
}; };
@ -325,19 +346,19 @@ export default class CipherService {
}); });
} }
async upsert(cipher: Data.Cipher | Data.Cipher[]): Promise<any> { async upsert(cipher: CipherData | CipherData[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
let ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>( let ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId); Keys.ciphersPrefix + userId);
if (ciphers == null) { if (ciphers == null) {
ciphers = {}; ciphers = {};
} }
if (cipher instanceof Data.Cipher) { if (cipher instanceof CipherData) {
const c = cipher as Data.Cipher; const c = cipher as CipherData;
ciphers[c.id] = c; ciphers[c.id] = c;
} else { } else {
(cipher as Data.Cipher[]).forEach((c) => { (cipher as CipherData[]).forEach((c) => {
ciphers[c.id] = c; ciphers[c.id] = c;
}); });
} }
@ -346,7 +367,7 @@ export default class CipherService {
this.decryptedCipherCache = null; this.decryptedCipherCache = null;
} }
async replace(ciphers: { [id: string]: Data.Cipher; }): Promise<any> { async replace(ciphers: { [id: string]: CipherData; }): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers); await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
this.decryptedCipherCache = null; this.decryptedCipherCache = null;
@ -359,7 +380,7 @@ export default class CipherService {
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();
const ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>( const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId); Keys.ciphersPrefix + userId);
if (ciphers == null) { if (ciphers == null) {
return; return;
@ -385,7 +406,7 @@ export default class CipherService {
async deleteAttachment(id: string, attachmentId: string): Promise<void> { async deleteAttachment(id: string, attachmentId: string): Promise<void> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>( const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
Keys.ciphersPrefix + userId); Keys.ciphersPrefix + userId);
if (ciphers == null || !ciphers.hasOwnProperty(id) || ciphers[id].attachments == null) { if (ciphers == null || !ciphers.hasOwnProperty(id) || ciphers[id].attachments == null) {
@ -406,7 +427,7 @@ export default class CipherService {
try { try {
await this.apiService.deleteCipherAttachment(id, attachmentId); await this.apiService.deleteCipherAttachment(id, attachmentId);
} catch (e) { } catch (e) {
return Promise.reject((e as Response.Error).getSingleMessage()); return Promise.reject((e as ErrorResponse).getSingleMessage());
} }
await this.deleteAttachment(id, attachmentId); await this.deleteAttachment(id, attachmentId);
} }
@ -421,7 +442,7 @@ export default class CipherService {
// Helpers // Helpers
private encryptObjProperty(model: any, obj: any, map: any, key: Domain.SymmetricCryptoKey): Promise<void[]> { private encryptObjProperty(model: any, obj: any, map: any, key: SymmetricCryptoKey): Promise<void[]> {
const promises = []; const promises = [];
const self = this; const self = this;
@ -438,7 +459,7 @@ export default class CipherService {
return self.cryptoService.encrypt(modelProp, key); return self.cryptoService.encrypt(modelProp, key);
} }
return null; return null;
}).then((val: Domain.CipherString) => { }).then((val: CipherString) => {
theObj[theProp] = val; theObj[theProp] = val;
}); });
promises.push(p); promises.push(p);
@ -448,9 +469,9 @@ export default class CipherService {
return Promise.all(promises); return Promise.all(promises);
} }
private encryptCipherData(cipher: Domain.Cipher, model: any, key: Domain.SymmetricCryptoKey): Promise<any> { private encryptCipherData(cipher: Cipher, model: any, key: SymmetricCryptoKey): Promise<any> {
switch (cipher.type) { switch (cipher.type) {
case Enums.CipherType.Login: case CipherType.Login:
model.login = {}; model.login = {};
return this.encryptObjProperty(cipher.login, model.login, { return this.encryptObjProperty(cipher.login, model.login, {
uri: null, uri: null,
@ -458,12 +479,12 @@ export default class CipherService {
password: null, password: null,
totp: null, totp: null,
}, key); }, key);
case Enums.CipherType.SecureNote: case CipherType.SecureNote:
model.secureNote = { model.secureNote = {
type: cipher.secureNote.type, type: cipher.secureNote.type,
}; };
return Promise.resolve(); return Promise.resolve();
case Enums.CipherType.Card: case CipherType.Card:
model.card = {}; model.card = {};
return this.encryptObjProperty(cipher.card, model.card, { return this.encryptObjProperty(cipher.card, model.card, {
cardholderName: null, cardholderName: null,
@ -473,7 +494,7 @@ export default class CipherService {
expYear: null, expYear: null,
code: null, code: null,
}, key); }, key);
case Enums.CipherType.Identity: case CipherType.Identity:
model.identity = {}; model.identity = {};
return this.encryptObjProperty(cipher.identity, model.identity, { return this.encryptObjProperty(cipher.identity, model.identity, {
title: null, title: null,

View File

@ -1,6 +1,13 @@
import UserService from './user.service'; import UserService from './user.service';
import { Abstractions, Data, Domain } from '@bitwarden/jslib'; import {
CryptoService,
StorageService,
} from 'jslib/abstractions';
import { CollectionData } from 'jslib/models/data';
import { Collection } from 'jslib/models/domain';
const Keys = { const Keys = {
collectionsPrefix: 'collections_', collectionsPrefix: 'collections_',
@ -9,33 +16,33 @@ const Keys = {
export default class CollectionService { export default class CollectionService {
decryptedCollectionCache: any[]; decryptedCollectionCache: any[];
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService, constructor(private cryptoService: CryptoService, private userService: UserService,
private storageService: Abstractions.StorageService) { private storageService: StorageService) {
} }
clearCache(): void { clearCache(): void {
this.decryptedCollectionCache = null; this.decryptedCollectionCache = null;
} }
async get(id: string): Promise<Domain.Collection> { async get(id: string): Promise<Collection> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const collections = await this.storageService.get<{ [id: string]: Data.Collection; }>( const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
Keys.collectionsPrefix + userId); Keys.collectionsPrefix + userId);
if (collections == null || !collections.hasOwnProperty(id)) { if (collections == null || !collections.hasOwnProperty(id)) {
return null; return null;
} }
return new Domain.Collection(collections[id]); return new Collection(collections[id]);
} }
async getAll(): Promise<Domain.Collection[]> { async getAll(): Promise<Collection[]> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const collections = await this.storageService.get<{ [id: string]: Data.Collection; }>( const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
Keys.collectionsPrefix + userId); Keys.collectionsPrefix + userId);
const response: Domain.Collection[] = []; const response: Collection[] = [];
for (const id in collections) { for (const id in collections) {
if (collections.hasOwnProperty(id)) { if (collections.hasOwnProperty(id)) {
response.push(new Domain.Collection(collections[id])); response.push(new Collection(collections[id]));
} }
} }
return response; return response;
@ -65,19 +72,19 @@ export default class CollectionService {
return this.decryptedCollectionCache; return this.decryptedCollectionCache;
} }
async upsert(collection: Data.Collection | Data.Collection[]): Promise<any> { async upsert(collection: CollectionData | CollectionData[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
let collections = await this.storageService.get<{ [id: string]: Data.Collection; }>( let collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
Keys.collectionsPrefix + userId); Keys.collectionsPrefix + userId);
if (collections == null) { if (collections == null) {
collections = {}; collections = {};
} }
if (collection instanceof Data.Collection) { if (collection instanceof CollectionData) {
const c = collection as Data.Collection; const c = collection as CollectionData;
collections[c.id] = c; collections[c.id] = c;
} else { } else {
(collection as Data.Collection[]).forEach((c) => { (collection as CollectionData[]).forEach((c) => {
collections[c.id] = c; collections[c.id] = c;
}); });
} }
@ -86,7 +93,7 @@ export default class CollectionService {
this.decryptedCollectionCache = null; this.decryptedCollectionCache = null;
} }
async replace(collections: { [id: string]: Data.Collection; }): Promise<any> { async replace(collections: { [id: string]: CollectionData; }): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
await this.storageService.save(Keys.collectionsPrefix + userId, collections); await this.storageService.save(Keys.collectionsPrefix + userId, collections);
this.decryptedCollectionCache = null; this.decryptedCollectionCache = null;
@ -99,7 +106,7 @@ export default class CollectionService {
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();
const collections = await this.storageService.get<{ [id: string]: Data.Collection; }>( const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
Keys.collectionsPrefix + userId); Keys.collectionsPrefix + userId);
if (collections == null) { if (collections == null) {
return; return;

View File

@ -1,4 +1,4 @@
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
export default class ConstantsService { export default class ConstantsService {
static readonly environmentUrlsKey: string = 'environmentUrls'; static readonly environmentUrlsKey: string = 'environmentUrls';
@ -57,7 +57,7 @@ export default class ConstantsService {
twoFactorProviderInfo: any[]; twoFactorProviderInfo: any[];
constructor(i18nService: any, platformUtilsService: Abstractions.PlatformUtilsService) { constructor(i18nService: any, platformUtilsService: PlatformUtilsService) {
if (platformUtilsService.isEdge()) { if (platformUtilsService.isEdge()) {
// delay for i18n fetch // delay for i18n fetch
setTimeout(() => { setTimeout(() => {

View File

@ -1,8 +1,11 @@
import { Abstractions } from '@bitwarden/jslib'; import {
CryptoService,
PlatformUtilsService,
} from 'jslib/abstractions';
export default class ContainerService { export default class ContainerService {
constructor(private cryptoService: Abstractions.CryptoService, constructor(private cryptoService: CryptoService,
private platformUtilsService: Abstractions.PlatformUtilsService) { private platformUtilsService: PlatformUtilsService) {
} }
attachToWindow(win: any) { attachToWindow(win: any) {
@ -11,11 +14,11 @@ export default class ContainerService {
} }
} }
getCryptoService(): Abstractions.CryptoService { getCryptoService(): CryptoService {
return this.cryptoService; return this.cryptoService;
} }
getPlatformUtilsService(): Abstractions.PlatformUtilsService { getPlatformUtilsService(): PlatformUtilsService {
return this.platformUtilsService; return this.platformUtilsService;
} }
} }

View File

@ -1,7 +1,9 @@
import ApiService from './api.service'; import ApiService from './api.service';
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
import { Abstractions, Domain } from '@bitwarden/jslib'; import { EnvironmentUrls } from 'jslib/models/domain';
import { StorageService } from 'jslib/abstractions';
export default class EnvironmentService { export default class EnvironmentService {
baseUrl: string; baseUrl: string;
@ -10,7 +12,7 @@ export default class EnvironmentService {
identityUrl: string; identityUrl: string;
iconsUrl: string; iconsUrl: string;
constructor(private apiService: ApiService, private storageService: Abstractions.StorageService) { constructor(private apiService: ApiService, private storageService: StorageService) {
} }
async setUrlsFromStorage(): Promise<void> { async setUrlsFromStorage(): Promise<void> {
@ -23,7 +25,7 @@ export default class EnvironmentService {
webVault: null, webVault: null,
}; };
const envUrls = new Domain.EnvironmentUrls(); const envUrls = new EnvironmentUrls();
if (urls.base) { if (urls.base) {
this.baseUrl = envUrls.base = urls.base; this.baseUrl = envUrls.base = urls.base;
@ -59,7 +61,7 @@ export default class EnvironmentService {
this.identityUrl = urls.identity; this.identityUrl = urls.identity;
this.iconsUrl = urls.icons; this.iconsUrl = urls.icons;
const envUrls = new Domain.EnvironmentUrls(); const envUrls = new EnvironmentUrls();
if (this.baseUrl) { if (this.baseUrl) {
envUrls.base = this.baseUrl; envUrls.base = this.baseUrl;
} else { } else {

View File

@ -1,7 +1,18 @@
import ApiService from './api.service'; import ApiService from './api.service';
import UserService from './user.service'; import UserService from './user.service';
import { Abstractions, Data, Domain, Request, Response } from '@bitwarden/jslib'; import { FolderData } from 'jslib/models/data';
import { Folder } from 'jslib/models/domain';
import { FolderRequest } from 'jslib/models/request';
import { FolderResponse } from 'jslib/models/response';
import {
CryptoService,
StorageService,
} from 'jslib/abstractions';
const Keys = { const Keys = {
foldersPrefix: 'folders_', foldersPrefix: 'folders_',
@ -10,41 +21,41 @@ const Keys = {
export default class FolderService { export default class FolderService {
decryptedFolderCache: any[]; decryptedFolderCache: any[];
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService, constructor(private cryptoService: CryptoService, private userService: UserService,
private i18nService: any, private apiService: ApiService, private i18nService: any, private apiService: ApiService,
private storageService: Abstractions.StorageService) { private storageService: StorageService) {
} }
clearCache(): void { clearCache(): void {
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
} }
async encrypt(model: any): Promise<Domain.Folder> { async encrypt(model: any): Promise<Folder> {
const folder = new Domain.Folder(); const folder = new Folder();
folder.id = model.id; folder.id = model.id;
folder.name = await this.cryptoService.encrypt(model.name); folder.name = await this.cryptoService.encrypt(model.name);
return folder; return folder;
} }
async get(id: string): Promise<Domain.Folder> { async get(id: string): Promise<Folder> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>( const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
Keys.foldersPrefix + userId); Keys.foldersPrefix + userId);
if (folders == null || !folders.hasOwnProperty(id)) { if (folders == null || !folders.hasOwnProperty(id)) {
return null; return null;
} }
return new Domain.Folder(folders[id]); return new Folder(folders[id]);
} }
async getAll(): Promise<Domain.Folder[]> { async getAll(): Promise<Folder[]> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>( const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
Keys.foldersPrefix + userId); Keys.foldersPrefix + userId);
const response: Domain.Folder[] = []; const response: Folder[] = [];
for (const id in folders) { for (const id in folders) {
if (folders.hasOwnProperty(id)) { if (folders.hasOwnProperty(id)) {
response.push(new Domain.Folder(folders[id])); response.push(new Folder(folders[id]));
} }
} }
return response; return response;
@ -78,10 +89,10 @@ export default class FolderService {
return this.decryptedFolderCache; return this.decryptedFolderCache;
} }
async saveWithServer(folder: Domain.Folder): Promise<any> { async saveWithServer(folder: Folder): Promise<any> {
const request = new Request.Folder(folder); const request = new FolderRequest(folder);
let response: Response.Folder; 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;
@ -90,23 +101,23 @@ export default class FolderService {
} }
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
const data = new Data.Folder(response, userId); const data = new FolderData(response, userId);
await this.upsert(data); await this.upsert(data);
} }
async upsert(folder: Data.Folder | Data.Folder[]): Promise<any> { async upsert(folder: FolderData | FolderData[]): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
let folders = await this.storageService.get<{ [id: string]: Data.Folder; }>( let folders = await this.storageService.get<{ [id: string]: FolderData; }>(
Keys.foldersPrefix + userId); Keys.foldersPrefix + userId);
if (folders == null) { if (folders == null) {
folders = {}; folders = {};
} }
if (folder instanceof Data.Folder) { if (folder instanceof FolderData) {
const f = folder as Data.Folder; const f = folder as FolderData;
folders[f.id] = f; folders[f.id] = f;
} else { } else {
(folder as Data.Folder[]).forEach((f) => { (folder as FolderData[]).forEach((f) => {
folders[f.id] = f; folders[f.id] = f;
}); });
} }
@ -115,7 +126,7 @@ export default class FolderService {
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
} }
async replace(folders: { [id: string]: Data.Folder; }): Promise<any> { async replace(folders: { [id: string]: FolderData; }): Promise<any> {
const userId = await this.userService.getUserId(); const userId = await this.userService.getUserId();
await this.storageService.save(Keys.foldersPrefix + userId, folders); await this.storageService.save(Keys.foldersPrefix + userId, folders);
this.decryptedFolderCache = null; this.decryptedFolderCache = null;
@ -128,7 +139,7 @@ export default class FolderService {
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();
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>( const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
Keys.foldersPrefix + userId); Keys.foldersPrefix + userId);
if (folders == null) { if (folders == null) {
return; return;

View File

@ -1,6 +1,6 @@
import { Abstractions } from '@bitwarden/jslib'; import { PlatformUtilsService } from 'jslib/abstractions';
export default function i18nService(platformUtilsService: Abstractions.PlatformUtilsService) { export default function i18nService(platformUtilsService: PlatformUtilsService) {
const edgeMessages: any = {}; const edgeMessages: any = {};
if (platformUtilsService.isEdge()) { if (platformUtilsService.isEdge()) {

View File

@ -3,13 +3,17 @@ import CollectionService from './collection.service';
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
import FolderService from './folder.service'; import FolderService from './folder.service';
import { Abstractions } from '@bitwarden/jslib'; import {
CryptoService,
PlatformUtilsService,
StorageService,
} from 'jslib/abstractions';
export default class LockService { export default class LockService {
constructor(private cipherService: CipherService, private folderService: FolderService, constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService, private cryptoService: Abstractions.CryptoService, private collectionService: CollectionService, private cryptoService: CryptoService,
private platformUtilsService: Abstractions.PlatformUtilsService, private platformUtilsService: PlatformUtilsService,
private storageService: Abstractions.StorageService, private storageService: StorageService,
private setIcon: Function, private refreshBadgeAndMenu: Function) { private setIcon: Function, private refreshBadgeAndMenu: Function) {
this.checkLock(); this.checkLock();
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds

View File

@ -1,4 +1,14 @@
import { Abstractions, Domain, Services } from '@bitwarden/jslib'; import {
CipherString,
PasswordHistory,
} from 'jslib/models/domain';
import { UtilsService } from 'jslib/services/utils.service';
import {
CryptoService,
StorageService,
} from 'jslib/abstractions';
const DefaultOptions = { const DefaultOptions = {
length: 14, length: 14,
@ -75,7 +85,7 @@ export default class PasswordGenerationService {
// shuffle // shuffle
positions.sort(() => { positions.sort(() => {
return Services.UtilsService.secureRandomNumber(0, 1) * 2 - 1; return UtilsService.secureRandomNumber(0, 1) * 2 - 1;
}); });
// build out the char sets // build out the char sets
@ -131,7 +141,7 @@ export default class PasswordGenerationService {
break; break;
} }
const randomCharIndex = Services.UtilsService.secureRandomNumber(0, positionChars.length - 1); const randomCharIndex = UtilsService.secureRandomNumber(0, positionChars.length - 1);
password += positionChars.charAt(randomCharIndex); password += positionChars.charAt(randomCharIndex);
} }
@ -139,11 +149,11 @@ export default class PasswordGenerationService {
} }
optionsCache: any; optionsCache: any;
history: Domain.PasswordHistory[] = []; history: PasswordHistory[] = [];
constructor(private cryptoService: Abstractions.CryptoService, constructor(private cryptoService: CryptoService,
private storageService: Abstractions.StorageService) { private storageService: StorageService) {
storageService.get<Domain.PasswordHistory[]>(Keys.history).then((encrypted) => { storageService.get<PasswordHistory[]>(Keys.history).then((encrypted) => {
return this.decryptHistory(encrypted); return this.decryptHistory(encrypted);
}).then((history) => { }).then((history) => {
this.history = history; this.history = history;
@ -173,7 +183,7 @@ export default class PasswordGenerationService {
} }
getHistory() { getHistory() {
return this.history || new Array<Domain.PasswordHistory>(); return this.history || new Array<PasswordHistory>();
} }
async addHistory(password: string): Promise<any> { async addHistory(password: string): Promise<any> {
@ -182,7 +192,7 @@ export default class PasswordGenerationService {
return; return;
} }
this.history.push(new Domain.PasswordHistory(password, Date.now())); this.history.push(new PasswordHistory(password, Date.now()));
// Remove old items. // Remove old items.
if (this.history.length > MaxPasswordsInHistory) { if (this.history.length > MaxPasswordsInHistory) {
@ -198,27 +208,27 @@ export default class PasswordGenerationService {
return await this.storageService.remove(Keys.history); return await this.storageService.remove(Keys.history);
} }
private async encryptHistory(): Promise<Domain.PasswordHistory[]> { private async encryptHistory(): Promise<PasswordHistory[]> {
if (this.history == null || this.history.length === 0) { if (this.history == null || this.history.length === 0) {
return Promise.resolve([]); return Promise.resolve([]);
} }
const promises = this.history.map(async (item) => { const promises = this.history.map(async (item) => {
const encrypted = await this.cryptoService.encrypt(item.password); const encrypted = await this.cryptoService.encrypt(item.password);
return new Domain.PasswordHistory(encrypted.encryptedString, item.date); return new PasswordHistory(encrypted.encryptedString, item.date);
}); });
return await Promise.all(promises); return await Promise.all(promises);
} }
private async decryptHistory(history: Domain.PasswordHistory[]): Promise<Domain.PasswordHistory[]> { private async decryptHistory(history: PasswordHistory[]): Promise<PasswordHistory[]> {
if (history == null || history.length === 0) { if (history == null || history.length === 0) {
return Promise.resolve([]); return Promise.resolve([]);
} }
const promises = history.map(async (item) => { const promises = history.map(async (item) => {
const decrypted = await this.cryptoService.decrypt(new Domain.CipherString(item.password)); const decrypted = await this.cryptoService.decrypt(new CipherString(item.password));
return new Domain.PasswordHistory(decrypted, item.date); return new PasswordHistory(decrypted, item.date);
}); });
return await Promise.all(promises); return await Promise.all(promises);

View File

@ -1,6 +1,6 @@
import UserService from './user.service'; import UserService from './user.service';
import { Abstractions } from '@bitwarden/jslib'; import { StorageService } from 'jslib/abstractions';
const Keys = { const Keys = {
settingsPrefix: 'settings_', settingsPrefix: 'settings_',
@ -10,7 +10,7 @@ const Keys = {
export default class SettingsService { export default class SettingsService {
private settingsCache: any; private settingsCache: any;
constructor(private userService: UserService, private storageService: Abstractions.StorageService) { constructor(private userService: UserService, private storageService: StorageService) {
} }
clearCache(): void { clearCache(): void {

View File

@ -5,7 +5,25 @@ import FolderService from './folder.service';
import SettingsService from './settings.service'; import SettingsService from './settings.service';
import UserService from './user.service'; import UserService from './user.service';
import { Abstractions, Data, Response } from '@bitwarden/jslib'; import {
CryptoService,
MessagingService,
StorageService,
} from 'jslib/abstractions';
import {
CipherData,
CollectionData,
FolderData,
} from 'jslib/models/data';
import {
CipherResponse,
CollectionResponse,
DomainsResponse,
FolderResponse,
ProfileResponse,
} from 'jslib/models/response';
const Keys = { const Keys = {
lastSyncPrefix: 'lastSync_', lastSyncPrefix: 'lastSync_',
@ -16,9 +34,9 @@ export default class SyncService {
constructor(private userService: UserService, private apiService: ApiService, constructor(private userService: UserService, private apiService: ApiService,
private settingsService: SettingsService, private folderService: FolderService, private settingsService: SettingsService, private folderService: FolderService,
private cipherService: CipherService, private cryptoService: Abstractions.CryptoService, private cipherService: CipherService, private cryptoService: CryptoService,
private collectionService: CollectionService, private storageService: Abstractions.StorageService, private collectionService: CollectionService, private storageService: StorageService,
private messagingService: Abstractions.MessagingService, private logoutCallback: Function) { private messagingService: MessagingService, private logoutCallback: Function) {
} }
async getLastSync() { async getLastSync() {
@ -110,7 +128,7 @@ export default class SyncService {
} }
} }
private async syncProfile(response: Response.Profile) { private async syncProfile(response: ProfileResponse) {
const stamp = await this.userService.getSecurityStamp(); const stamp = await this.userService.getSecurityStamp();
if (stamp != null && stamp !== response.securityStamp) { if (stamp != null && stamp !== response.securityStamp) {
if (this.logoutCallback != null) { if (this.logoutCallback != null) {
@ -126,31 +144,31 @@ export default class SyncService {
await this.userService.setSecurityStamp(response.securityStamp); await this.userService.setSecurityStamp(response.securityStamp);
} }
private async syncFolders(userId: string, response: Response.Folder[]) { private async syncFolders(userId: string, response: FolderResponse[]) {
const folders: { [id: string]: Data.Folder; } = {}; const folders: { [id: string]: FolderData; } = {};
response.forEach((f) => { response.forEach((f) => {
folders[f.id] = new Data.Folder(f, userId); folders[f.id] = new FolderData(f, userId);
}); });
return await this.folderService.replace(folders); return await this.folderService.replace(folders);
} }
private async syncCollections(response: Response.Collection[]) { private async syncCollections(response: CollectionResponse[]) {
const collections: { [id: string]: Data.Collection; } = {}; const collections: { [id: string]: CollectionData; } = {};
response.forEach((c) => { response.forEach((c) => {
collections[c.id] = new Data.Collection(c); collections[c.id] = new CollectionData(c);
}); });
return await this.collectionService.replace(collections); return await this.collectionService.replace(collections);
} }
private async syncCiphers(userId: string, response: Response.Cipher[]) { private async syncCiphers(userId: string, response: CipherResponse[]) {
const ciphers: { [id: string]: Data.Cipher; } = {}; const ciphers: { [id: string]: CipherData; } = {};
response.forEach((c) => { response.forEach((c) => {
ciphers[c.id] = new Data.Cipher(c, userId); ciphers[c.id] = new CipherData(c, userId);
}); });
return await this.cipherService.replace(ciphers); return await this.cipherService.replace(ciphers);
} }
private async syncSettings(userId: string, response: Response.Domains) { private async syncSettings(userId: string, response: DomainsResponse) {
let eqDomains: string[][] = []; let eqDomains: string[][] = [];
if (response != null && response.equivalentDomains != null) { if (response != null && response.equivalentDomains != null) {
eqDomains = eqDomains.concat(response.equivalentDomains); eqDomains = eqDomains.concat(response.equivalentDomains);

View File

@ -1,6 +1,8 @@
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
import { Abstractions, Services } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/services/utils.service';
import { StorageService } from 'jslib/abstractions';
const Keys = { const Keys = {
accessToken: 'accessToken', accessToken: 'accessToken',
@ -13,7 +15,7 @@ export default class TokenService {
decodedToken: any; decodedToken: any;
refreshToken: string; refreshToken: string;
constructor(private storageService: Abstractions.StorageService) { constructor(private storageService: StorageService) {
} }
setTokens(accessToken: string, refreshToken: string): Promise<any> { setTokens(accessToken: string, refreshToken: string): Promise<any> {
@ -92,7 +94,7 @@ export default class TokenService {
throw new Error('JWT must have 3 parts'); throw new Error('JWT must have 3 parts');
} }
const decoded = Services.UtilsService.urlBase64Decode(parts[1]); const decoded = UtilsService.urlBase64Decode(parts[1]);
if (decoded == null) { if (decoded == null) {
throw new Error('Cannot decode the token'); throw new Error('Cannot decode the token');
} }

View File

@ -1,6 +1,6 @@
import ConstantsService from './constants.service'; import ConstantsService from './constants.service';
import { Abstractions } from '@bitwarden/jslib'; import { StorageService } from 'jslib/abstractions';
const b32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; const b32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
@ -10,7 +10,7 @@ const TotpAlgorithm = {
}; };
export default class TotpService { export default class TotpService {
constructor(private storageService: Abstractions.StorageService) { constructor(private storageService: StorageService) {
} }
async getCode(keyb32: string): Promise<string> { async getCode(keyb32: string): Promise<string> {

View File

@ -1,6 +1,6 @@
import TokenService from './token.service'; import TokenService from './token.service';
import { Abstractions } from '@bitwarden/jslib'; import { StorageService } from 'jslib/abstractions';
const Keys = { const Keys = {
userId: 'userId', userId: 'userId',
@ -13,7 +13,7 @@ export default class UserService {
email: string; email: string;
stamp: string; stamp: string;
constructor(private tokenService: TokenService, private storageService: Abstractions.StorageService) { constructor(private tokenService: TokenService, private storageService: StorageService) {
} }
setUserIdAndEmail(userId: string, email: string): Promise<any> { setUserIdAndEmail(userId: string, email: string): Promise<any> {

View File

@ -1,32 +1,32 @@
import { Services } from '@bitwarden/jslib'; import { UtilsService } from 'jslib/services';
describe('Utils Service', () => { describe('Utils Service', () => {
describe('getHostname', () => { describe('getHostname', () => {
it('should fail for invalid urls', () => { it('should fail for invalid urls', () => {
expect(Services.UtilsService.getHostname(null)).toBeNull(); expect(UtilsService.getHostname(null)).toBeNull();
expect(Services.UtilsService.getHostname(undefined)).toBeNull(); expect(UtilsService.getHostname(undefined)).toBeNull();
expect(Services.UtilsService.getHostname(' ')).toBeNull(); expect(UtilsService.getHostname(' ')).toBeNull();
expect(Services.UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull(); expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
expect(Services.UtilsService.getHostname('bitwarden')).toBeNull(); expect(UtilsService.getHostname('bitwarden')).toBeNull();
}); });
it('should handle valid urls', () => { it('should handle valid urls', () => {
expect(Services.UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com'); expect(UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
expect(Services.UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com'); expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
expect(Services.UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com'); expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
expect(Services.UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com'); expect(UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
}); });
it('should support localhost and IP', () => { it('should support localhost and IP', () => {
expect(Services.UtilsService.getHostname('https://localhost')).toBe('localhost'); expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
expect(Services.UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1'); expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
}); });
}); });
describe('newGuid', () => { describe('newGuid', () => {
it('should create a valid guid', () => { it('should create a valid guid', () => {
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
expect(Services.UtilsService.newGuid()).toMatch(validGuid); expect(UtilsService.newGuid()).toMatch(validGuid);
}); });
}); });
}); });

View File

@ -8,7 +8,11 @@
"sourceMap": true, "sourceMap": true,
"types": [ "types": [
"jasmine" "jasmine"
] ],
"baseUrl": ".",
"paths": {
"jslib/*": [ "node_modules/@bitwarden/jslib/src/*" ]
}
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",

View File

@ -103,7 +103,10 @@ module.exports = {
]) ])
], ],
resolve: { resolve: {
extensions: ['.tsx', '.ts', '.js'] extensions: ['.tsx', '.ts', '.js'],
alias: {
jslib: path.join(__dirname, 'node_modules/@bitwarden/jslib/src')
}
}, },
output: { output: {
filename: '[name].js', filename: '[name].js',