mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
import ts through node_modules alias
This commit is contained in:
parent
e165b5cc70
commit
f51bebd99a
@ -4,7 +4,7 @@ import MainBackground from './main.background';
|
||||
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
import { UtilsService } from 'jslib/services/utils.service';
|
||||
|
||||
export default class CommandsBackground {
|
||||
private commands: any;
|
||||
@ -35,7 +35,7 @@ export default class CommandsBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
|
@ -5,7 +5,7 @@ import MainBackground from './main.background';
|
||||
import CipherService from '../services/cipher.service';
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
import { UtilsService } from 'jslib/services/utils.service';
|
||||
|
||||
export default class ContextMenusBackground {
|
||||
private contextMenus: any;
|
||||
@ -33,7 +33,7 @@ export default class ContextMenusBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
@ -69,13 +69,13 @@ export default class ContextMenusBackground {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Username From Context Menu',
|
||||
});
|
||||
Services.UtilsService.copyToClipboard(cipher.login.username);
|
||||
UtilsService.copyToClipboard(cipher.login.username);
|
||||
} else if (info.parentMenuItemId === 'copy-password') {
|
||||
(window as any).ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Password From Context Menu',
|
||||
});
|
||||
Services.UtilsService.copyToClipboard(cipher.login.password);
|
||||
UtilsService.copyToClipboard(cipher.login.password);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -2,13 +2,13 @@ import ConstantsService from '../services/constants.service';
|
||||
import LockService from '../services/lock.service';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
export default class IdleBackground {
|
||||
private idle: any;
|
||||
|
||||
constructor(private main: MainBackground, private lockService: LockService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
private storageService: StorageService) {
|
||||
this.idle = chrome.idle;
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
||||
@ -32,13 +45,13 @@ import TotpService from '../services/totp.service';
|
||||
import UserService from '../services/user.service';
|
||||
|
||||
export default class MainBackground {
|
||||
messagingService: Abstractions.MessagingService;
|
||||
storageService: Abstractions.StorageService;
|
||||
messagingService: MessagingServiceAbstraction;
|
||||
storageService: StorageServiceAbstraction;
|
||||
i18nService: any;
|
||||
platformUtilsService: Abstractions.PlatformUtilsService;
|
||||
utilsService: Abstractions.UtilsService;
|
||||
platformUtilsService: PlatformUtilsServiceAbstraction;
|
||||
utilsService: UtilsServiceAbstraction;
|
||||
constantsService: ConstantsService;
|
||||
cryptoService: Abstractions.CryptoService;
|
||||
cryptoService: CryptoServiceAbstraction;
|
||||
tokenService: TokenService;
|
||||
appIdService: AppIdService;
|
||||
apiService: ApiService;
|
||||
@ -75,13 +88,13 @@ export default class MainBackground {
|
||||
|
||||
constructor() {
|
||||
// Services
|
||||
this.utilsService = new Services.UtilsService();
|
||||
this.utilsService = new UtilsService();
|
||||
this.platformUtilsService = new BrowserPlatformUtilsService();
|
||||
this.messagingService = new BrowserMessagingService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.i18nService = 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.tokenService = new TokenService(this.storageService);
|
||||
this.appIdService = new AppIdService(this.storageService);
|
||||
@ -346,7 +359,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
private async loadLoginContextMenuOptions(cipher: any) {
|
||||
if (cipher == null || cipher.type !== Enums.CipherType.Login) {
|
||||
if (cipher == null || cipher.type !== CipherType.Login) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -363,7 +376,7 @@ export default class MainBackground {
|
||||
|
||||
private async loadContextMenuOptions(title: string, idSuffix: string, cipher: any) {
|
||||
if (!chrome.contextMenus || this.menuOptionsLoaded.indexOf(idSuffix) > -1 ||
|
||||
(cipher != null && cipher.type !== Enums.CipherType.Login)) {
|
||||
(cipher != null && cipher.type !== CipherType.Login)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
||||
@ -13,7 +19,7 @@ export default class RuntimeBackground {
|
||||
private pageDetailsToAutoFill: any[] = [];
|
||||
|
||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||
private cipherService: CipherService, private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService) {
|
||||
this.runtime = chrome.runtime;
|
||||
}
|
||||
|
||||
@ -146,7 +152,7 @@ export default class RuntimeBackground {
|
||||
favorite: false,
|
||||
name: loginInfo.name,
|
||||
notes: null,
|
||||
type: Enums.CipherType.Login,
|
||||
type: CipherType.Login,
|
||||
login: {
|
||||
uri: loginInfo.uri,
|
||||
username: loginInfo.username,
|
||||
@ -177,7 +183,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
this.main.loginsToAdd.splice(i, 1);
|
||||
const hostname = Services.UtilsService.getHostname(tab.url);
|
||||
const hostname = UtilsService.getHostname(tab.url);
|
||||
await this.cipherService.saveNeverDomain(hostname);
|
||||
BrowserApi.tabSendMessage(tab, 'closeNotificationBar');
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import CipherService from '../services/cipher.service';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
export default class WebRequestBackground {
|
||||
private pendingAuthRequests: any[] = [];
|
||||
private webRequest: any;
|
||||
private isFirefox: boolean;
|
||||
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
constructor(private platformUtilsService: PlatformUtilsService,
|
||||
private cipherService: CipherService) {
|
||||
this.webRequest = (window as any).chrome.webRequest;
|
||||
this.isFirefox = platformUtilsService.isFirefox();
|
||||
|
@ -30,7 +30,19 @@ import GlobalModule from './global/global.module';
|
||||
import SettingsModule from './settings/settings.module';
|
||||
|
||||
// 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
|
||||
.module('bit', [
|
||||
|
@ -1,6 +1,6 @@
|
||||
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 {
|
||||
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,
|
||||
private $timeout: any, private $window: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
private platformUtilsService: PlatformUtilsService) {
|
||||
this.i18n = i18nService;
|
||||
this.constants = constantsService;
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
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 {
|
||||
i18n: any;
|
||||
|
||||
constructor(private $analytics: any, private $window: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private i18nService: any) {
|
||||
this.i18n = i18nService;
|
||||
}
|
||||
|
@ -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';
|
||||
|
||||
@ -17,8 +20,8 @@ export class CurrentController {
|
||||
disableSearch: boolean = false;
|
||||
|
||||
constructor($scope: any, private cipherService: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private utilsService: Abstractions.UtilsService, private toastr: any, private $window: any, private $state: any,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
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 $filter: any) {
|
||||
this.i18n = i18nService;
|
||||
@ -117,8 +120,8 @@ export class CurrentController {
|
||||
});
|
||||
|
||||
const otherTypes = [
|
||||
Enums.CipherType.Card,
|
||||
Enums.CipherType.Identity,
|
||||
CipherType.Card,
|
||||
CipherType.Identity,
|
||||
];
|
||||
|
||||
this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any[]) => {
|
||||
@ -131,13 +134,13 @@ export class CurrentController {
|
||||
|
||||
sortedCiphers.forEach((cipher: any) => {
|
||||
switch (cipher.type) {
|
||||
case Enums.CipherType.Login:
|
||||
case CipherType.Login:
|
||||
loginCiphers.push(cipher);
|
||||
break;
|
||||
case Enums.CipherType.Card:
|
||||
case CipherType.Card:
|
||||
cardCiphers.push(cipher);
|
||||
break;
|
||||
case Enums.CipherType.Identity:
|
||||
case CipherType.Identity:
|
||||
identityCiphers.push(cipher);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { UtilsService } from 'jslib/abstractions/utils.service';
|
||||
|
||||
export class MainController implements ng.IController {
|
||||
smBody: boolean;
|
||||
@ -6,7 +6,7 @@ export class MainController implements ng.IController {
|
||||
animation: string;
|
||||
|
||||
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.xsBody = $window.screen.availHeight < 600;
|
||||
this.smBody = !this.xsBody && $window.screen.availHeight <= 800;
|
||||
|
@ -1,16 +1,18 @@
|
||||
import * as angular from 'angular';
|
||||
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 {
|
||||
i18n: any;
|
||||
masterPassword: string;
|
||||
|
||||
constructor(public $state: any, public i18nService: any, private $timeout: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
public cryptoService: Abstractions.CryptoService, public toastr: any, public userService: any,
|
||||
public messagingService: Abstractions.MessagingService, public SweetAlert: any) {
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
public cryptoService: CryptoService, public toastr: any, public userService: any,
|
||||
public messagingService: MessagingService, public SweetAlert: any) {
|
||||
this.i18n = i18nService;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
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 {
|
||||
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 platformUtilsService: Abstractions.PlatformUtilsService, public constantsService: any,
|
||||
public messagingService: Abstractions.MessagingService) {
|
||||
public platformUtilsService: PlatformUtilsService, public constantsService: any,
|
||||
public messagingService: MessagingService) {
|
||||
}
|
||||
|
||||
async logIn(email: string, masterPassword: string, twoFactorProvider?: number,
|
||||
@ -16,18 +21,18 @@ class AuthService {
|
||||
const storedTwoFactorToken = await this.tokenService.getTwoFactorToken(email);
|
||||
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) {
|
||||
request = new Request.Token(email, hashedPassword, twoFactorProvider, twoFactorToken, remember,
|
||||
request = new TokenRequest(email, hashedPassword, twoFactorProvider, twoFactorToken, remember,
|
||||
deviceRequest);
|
||||
} 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);
|
||||
} 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);
|
||||
|
@ -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) {
|
||||
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 cryptoService = getBackgroundService<any>('cryptoService');
|
||||
export const userService = getBackgroundService<any>('userService');
|
||||
export const apiService = getBackgroundService<any>('apiService');
|
||||
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 autofillService = getBackgroundService<any>('autofillService');
|
||||
export const passwordGenerationService = getBackgroundService<any>('passwordGenerationService');
|
||||
export const platformUtilsService = getBackgroundService<Abstractions.PlatformUtilsService>('platformUtilsService');
|
||||
export const utilsService = getBackgroundService<Abstractions.UtilsService>('utilsService');
|
||||
export const platformUtilsService = getBackgroundService<PlatformUtilsService>('platformUtilsService');
|
||||
export const utilsService = getBackgroundService<UtilsService>('utilsService');
|
||||
export const appIdService = getBackgroundService<any>('appIdService');
|
||||
export const i18nService = getBackgroundService<any>('i18nService');
|
||||
export const constantsService = getBackgroundService<any>('constantsService');
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
|
||||
class StateService {
|
||||
private state: any = {};
|
||||
|
||||
constructor(private storageService: Abstractions.StorageService, private constantsService: any) {
|
||||
constructor(private storageService: StorageService, private constantsService: any) {
|
||||
}
|
||||
|
||||
async init() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import * as template from './environment.component.html';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
|
||||
export class EnvironmentController {
|
||||
iconsUrl: string;
|
||||
@ -12,7 +12,7 @@ export class EnvironmentController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any,
|
||||
platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
platformUtilsService: PlatformUtilsService,
|
||||
private environmentService: any, private toastr: any, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
import * as angular from 'angular';
|
||||
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 {
|
||||
savePromise: any;
|
||||
@ -9,7 +11,7 @@ export class AddFolderController {
|
||||
i18n: 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(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
@ -28,7 +30,7 @@ export class AddFolderController {
|
||||
}
|
||||
|
||||
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);
|
||||
}).then((folder: any) => {
|
||||
this.$analytics.eventTrack('Added Folder');
|
||||
|
@ -1,17 +1,19 @@
|
||||
import * as angular from 'angular';
|
||||
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 {
|
||||
$transition$: any;
|
||||
folderId: any;
|
||||
savePromise: any = null;
|
||||
i18n: any;
|
||||
folder: Domain.Folder;
|
||||
folder: Folder;
|
||||
|
||||
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) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
@ -27,7 +29,7 @@ export class EditFolderController {
|
||||
this.folderId = this.$transition$.params('to').folderId;
|
||||
this.folderService.get(this.folderId).then((folder: any) => {
|
||||
return folder.decrypt();
|
||||
}).then((model: Domain.Folder) => {
|
||||
}).then((model: Folder) => {
|
||||
this.folder = model;
|
||||
});
|
||||
}
|
||||
@ -39,7 +41,7 @@ export class EditFolderController {
|
||||
}
|
||||
|
||||
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);
|
||||
}).then((folder: any) => {
|
||||
this.$analytics.eventTrack('Edited Folder');
|
||||
|
@ -1,9 +1,9 @@
|
||||
import * as template from './folders.component.html';
|
||||
|
||||
import { Domain } from '@bitwarden/jslib';
|
||||
import { Folder } from 'jslib/models/domain';
|
||||
|
||||
export class FoldersController {
|
||||
folders: Domain.Folder[] = [];
|
||||
folders: Folder[] = [];
|
||||
i18n: any;
|
||||
loaded = false;
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
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 * as template from './options.component.html';
|
||||
@ -15,9 +17,9 @@ export class OptionsController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, private constantsService: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService, private totpService: any,
|
||||
private stateService: StateService, private storageService: Abstractions.StorageService,
|
||||
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
private platformUtilsService: PlatformUtilsService, private totpService: any,
|
||||
private stateService: StateService, private storageService: StorageService,
|
||||
public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
|
@ -1,23 +1,28 @@
|
||||
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 * as template from './settings.component.html';
|
||||
|
||||
const RateUrls = {
|
||||
[Enums.DeviceType.Chrome]:
|
||||
[DeviceType.Chrome]:
|
||||
'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',
|
||||
[Enums.DeviceType.Opera]:
|
||||
[DeviceType.Opera]:
|
||||
'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',
|
||||
[Enums.DeviceType.Vivaldi]:
|
||||
[DeviceType.Vivaldi]:
|
||||
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
|
||||
[Enums.DeviceType.Safari]:
|
||||
[DeviceType.Safari]:
|
||||
'https://itunes.com', // TODO
|
||||
};
|
||||
|
||||
@ -27,11 +32,11 @@ export class SettingsController {
|
||||
showOnLocked: boolean;
|
||||
|
||||
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 cryptoService: Abstractions.CryptoService, private lockService: any,
|
||||
private storageService: Abstractions.StorageService,
|
||||
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
private cryptoService: CryptoService, private lockService: any,
|
||||
private storageService: StorageService,
|
||||
public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
|
@ -2,14 +2,17 @@ import * as angular from 'angular';
|
||||
import * as papa from 'papaparse';
|
||||
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 {
|
||||
i18n: any;
|
||||
masterPassword: string;
|
||||
|
||||
constructor(private $state: any, private cryptoService: Abstractions.CryptoService,
|
||||
private toastr: any, private utilsService: Abstractions.UtilsService, private $analytics: any,
|
||||
constructor(private $state: any, private cryptoService: CryptoService,
|
||||
private toastr: any, private utilsService: UtilsService, private $analytics: any,
|
||||
private i18nService: any, private folderService: any, private cipherService: any,
|
||||
private $window: any, private userService: any) {
|
||||
this.i18n = i18nService;
|
||||
@ -72,7 +75,7 @@ export class ExportController {
|
||||
const exportCiphers = [];
|
||||
for (const c of decCiphers) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -103,14 +106,14 @@ export class ExportController {
|
||||
}
|
||||
|
||||
switch (c.type) {
|
||||
case Enums.CipherType.Login:
|
||||
case CipherType.Login:
|
||||
cipher.type = 'login';
|
||||
cipher.login_uri = c.login.uri;
|
||||
cipher.login_username = c.login.username;
|
||||
cipher.login_password = c.login.password;
|
||||
cipher.login_totp = c.login.totp;
|
||||
break;
|
||||
case Enums.CipherType.SecureNote:
|
||||
case CipherType.SecureNote:
|
||||
cipher.type = 'note';
|
||||
break;
|
||||
default:
|
||||
|
@ -1,10 +1,10 @@
|
||||
import * as template from './password-generator-history.component.html';
|
||||
|
||||
import { Domain } from '@bitwarden/jslib';
|
||||
import { PasswordHistory } from 'jslib/models/domain/passwordHistory';
|
||||
|
||||
export class PasswordGeneratorHistoryController {
|
||||
$transition$: any;
|
||||
history: Domain.PasswordHistory[];
|
||||
history: PasswordHistory[];
|
||||
editState: any;
|
||||
addState: any;
|
||||
i18n: any;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import * as template from './password-generator.component.html';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
export class PasswordGeneratorController {
|
||||
$transition$: any;
|
||||
@ -13,7 +13,7 @@ export class PasswordGeneratorController {
|
||||
i18n: 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) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as template from './tools.component.html';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
export class ToolsController {
|
||||
showExport: boolean;
|
||||
@ -8,7 +8,7 @@ export class ToolsController {
|
||||
private webVaultBaseUrl: string = 'https://vault.bitwarden.com';
|
||||
|
||||
constructor(private SweetAlert: any, private i18nService: any,
|
||||
private $analytics: any, private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private $analytics: any, private platformUtilsService: PlatformUtilsService,
|
||||
private environmentService: any) {
|
||||
this.i18n = i18nService;
|
||||
this.showExport = !platformUtilsService.isEdge();
|
||||
|
@ -2,7 +2,36 @@ import AppIdService from './appId.service';
|
||||
import ConstantsService from './constants.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 {
|
||||
urlsSet: boolean = false;
|
||||
@ -11,13 +40,13 @@ export default class ApiService {
|
||||
deviceType: string;
|
||||
logoutCallback: Function;
|
||||
|
||||
constructor(private tokenService: TokenService, platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
constructor(private tokenService: TokenService, platformUtilsService: PlatformUtilsService,
|
||||
logoutCallback: Function) {
|
||||
this.logoutCallback = logoutCallback;
|
||||
this.deviceType = platformUtilsService.getDevice().toString();
|
||||
}
|
||||
|
||||
setUrls(urls: Domain.EnvironmentUrls) {
|
||||
setUrls(urls: EnvironmentUrls) {
|
||||
this.urlsSet = true;
|
||||
|
||||
if (urls.base != null) {
|
||||
@ -57,7 +86,7 @@ export default class ApiService {
|
||||
|
||||
// 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', {
|
||||
body: this.qsStringify(request.toIdentityToken()),
|
||||
cache: 'no-cache',
|
||||
@ -77,7 +106,7 @@ export default class ApiService {
|
||||
|
||||
if (responseJson != null) {
|
||||
if (response.status === 200) {
|
||||
return new Res.IdentityToken(responseJson);
|
||||
return new IdentityTokenResponse(responseJson);
|
||||
} else if (response.status === 400 && responseJson.TwoFactorProviders2 &&
|
||||
Object.keys(responseJson.TwoFactorProviders2).length) {
|
||||
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> {
|
||||
@ -98,7 +127,7 @@ export default class ApiService {
|
||||
|
||||
// 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', {
|
||||
body: JSON.stringify(request),
|
||||
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', {
|
||||
body: JSON.stringify(request),
|
||||
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', {
|
||||
body: JSON.stringify(request),
|
||||
cache: 'no-cache',
|
||||
@ -172,7 +201,7 @@ export default class ApiService {
|
||||
|
||||
// Folder APIs
|
||||
|
||||
async postFolder(request: Req.Folder): Promise<Res.Folder> {
|
||||
async postFolder(request: FolderRequest): Promise<FolderResponse> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/folders', {
|
||||
body: JSON.stringify(request),
|
||||
@ -188,14 +217,14 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Folder(responseJson);
|
||||
return new FolderResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
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 response = await fetch(new Request(this.baseUrl + '/folders/' + id, {
|
||||
body: JSON.stringify(request),
|
||||
@ -211,7 +240,7 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Folder(responseJson);
|
||||
return new FolderResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
@ -237,7 +266,7 @@ export default class ApiService {
|
||||
|
||||
// Cipher APIs
|
||||
|
||||
async postCipher(request: Req.Cipher): Promise<Res.Cipher> {
|
||||
async postCipher(request: CipherRequest): Promise<CipherResponse> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/ciphers', {
|
||||
body: JSON.stringify(request),
|
||||
@ -253,14 +282,14 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Cipher(responseJson);
|
||||
return new CipherResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
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 response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
|
||||
body: JSON.stringify(request),
|
||||
@ -276,7 +305,7 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Cipher(responseJson);
|
||||
return new CipherResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
@ -302,7 +331,7 @@ export default class ApiService {
|
||||
|
||||
// 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 response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', {
|
||||
body: data,
|
||||
@ -317,7 +346,7 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Cipher(responseJson);
|
||||
return new CipherResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
@ -343,7 +372,7 @@ export default class ApiService {
|
||||
|
||||
// Sync APIs
|
||||
|
||||
async getSync(): Promise<Res.Sync> {
|
||||
async getSync(): Promise<SyncResponse> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/sync', {
|
||||
cache: 'no-cache',
|
||||
@ -356,7 +385,7 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
return new Res.Sync(responseJson);
|
||||
return new SyncResponse(responseJson);
|
||||
} else {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
@ -365,7 +394,7 @@ export default class ApiService {
|
||||
|
||||
// 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) {
|
||||
this.logoutCallback(true);
|
||||
return null;
|
||||
@ -377,7 +406,7 @@ export default class ApiService {
|
||||
responseJson = await response.json();
|
||||
}
|
||||
|
||||
return new Res.Error(responseJson, response.status, tokenError);
|
||||
return new ErrorResponse(responseJson, response.status, tokenError);
|
||||
}
|
||||
|
||||
private async handleTokenState(): Promise<string> {
|
||||
@ -392,7 +421,7 @@ export default class ApiService {
|
||||
return 'Bearer ' + accessToken;
|
||||
}
|
||||
|
||||
private async doRefreshToken(): Promise<Res.IdentityToken> {
|
||||
private async doRefreshToken(): Promise<IdentityTokenResponse> {
|
||||
const refreshToken = await this.tokenService.getRefreshToken();
|
||||
if (refreshToken == null || refreshToken === '') {
|
||||
throw new Error();
|
||||
@ -415,7 +444,7 @@ export default class ApiService {
|
||||
|
||||
if (response.status === 200) {
|
||||
const responseJson = await response.json();
|
||||
const tokenResponse = new Res.IdentityToken(responseJson);
|
||||
const tokenResponse = new IdentityTokenResponse(responseJson);
|
||||
await this.tokenService.setTokens(tokenResponse.accessToken, tokenResponse.refreshToken);
|
||||
return tokenResponse;
|
||||
} else {
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { Abstractions, Services } from '@bitwarden/jslib';
|
||||
import { UtilsService } from 'jslib/services';
|
||||
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
export default class AppIdService {
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
constructor(private storageService: StorageService) {
|
||||
}
|
||||
|
||||
getAppId(): Promise<string> {
|
||||
@ -18,7 +20,7 @@ export default class AppIdService {
|
||||
return existingId;
|
||||
}
|
||||
|
||||
const guid = Services.UtilsService.newGuid();
|
||||
const guid = UtilsService.newGuid();
|
||||
await this.storageService.save(key, guid);
|
||||
return guid;
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
import {
|
||||
CipherType,
|
||||
FieldType,
|
||||
} from 'jslib/enums';
|
||||
|
||||
import AutofillField from '../models/domain/autofillField';
|
||||
import AutofillPageDetails from '../models/domain/autofillPageDetails';
|
||||
@ -8,6 +11,13 @@ import CipherService from './cipher.service';
|
||||
import TokenService from './token.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',
|
||||
'placeholder', 'label-left', 'label-top'];
|
||||
|
||||
@ -90,8 +100,8 @@ var IsoProvinces: { [id: string]: string; } = {
|
||||
|
||||
export default class AutofillService {
|
||||
constructor(public cipherService: CipherService, public tokenService: TokenService,
|
||||
public totpService: TotpService, public utilsService: Services.UtilsService,
|
||||
public platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
public totpService: TotpService, public utilsService: UtilsServiceAbstraction,
|
||||
public platformUtilsService: PlatformUtilsService) {
|
||||
}
|
||||
|
||||
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
|
||||
@ -165,7 +175,7 @@ export default class AutofillService {
|
||||
fillScript: fillScript,
|
||||
}, { 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.cipher.login.totp || !this.tokenService.getPremium()) {
|
||||
return;
|
||||
@ -179,7 +189,7 @@ export default class AutofillService {
|
||||
return null;
|
||||
}).then((code: string) => {
|
||||
if (code) {
|
||||
Services.UtilsService.copyToClipboard(code);
|
||||
UtilsService.copyToClipboard(code);
|
||||
}
|
||||
|
||||
return code;
|
||||
@ -267,7 +277,7 @@ export default class AutofillService {
|
||||
const matchingIndex = this.findMatchingFieldIndex(field, fieldNames);
|
||||
if (matchingIndex > -1) {
|
||||
let val = fields[matchingIndex].value;
|
||||
if (val == null && fields[matchingIndex].type === Enums.FieldType.Boolean) {
|
||||
if (val == null && fields[matchingIndex].type === FieldType.Boolean) {
|
||||
val = 'false';
|
||||
}
|
||||
|
||||
@ -279,13 +289,13 @@ export default class AutofillService {
|
||||
}
|
||||
|
||||
switch (options.cipher.type) {
|
||||
case Enums.CipherType.Login:
|
||||
case CipherType.Login:
|
||||
fillScript = this.generateLoginFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
case Enums.CipherType.Card:
|
||||
case CipherType.Card:
|
||||
fillScript = this.generateCardFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
case Enums.CipherType.Identity:
|
||||
case CipherType.Identity:
|
||||
fillScript = this.generateIdentityFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import {
|
||||
MessagingService,
|
||||
PlatformUtilsService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class BrowserMessagingService implements Abstractions.MessagingService {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
export default class BrowserMessagingService implements MessagingService {
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {
|
||||
}
|
||||
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import BrowserPlatformUtilsService from './browserPlatformUtils.service';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { DeviceType } from 'jslib/enums';
|
||||
|
||||
describe('Browser Utils Service', () => {
|
||||
describe('getDomain', () => {
|
||||
@ -48,7 +49,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Chrome);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Chrome);
|
||||
});
|
||||
|
||||
it('should detect firefox', () => {
|
||||
@ -58,7 +59,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Firefox);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Firefox);
|
||||
});
|
||||
|
||||
it('should detect opera', () => {
|
||||
@ -68,7 +69,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Opera);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Opera);
|
||||
});
|
||||
|
||||
it('should detect edge', () => {
|
||||
@ -78,7 +79,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Edge);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Edge);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,17 +1,19 @@
|
||||
import * as tldjs from 'tldjs';
|
||||
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
import { DeviceType } from 'jslib/enums';
|
||||
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
const AnalyticsIds = {
|
||||
[Enums.DeviceType.Chrome]: 'UA-81915606-6',
|
||||
[Enums.DeviceType.Firefox]: 'UA-81915606-7',
|
||||
[Enums.DeviceType.Opera]: 'UA-81915606-8',
|
||||
[Enums.DeviceType.Edge]: 'UA-81915606-9',
|
||||
[Enums.DeviceType.Vivaldi]: 'UA-81915606-15',
|
||||
[Enums.DeviceType.Safari]: 'UA-81915606-16',
|
||||
[DeviceType.Chrome]: 'UA-81915606-6',
|
||||
[DeviceType.Firefox]: 'UA-81915606-7',
|
||||
[DeviceType.Opera]: 'UA-81915606-8',
|
||||
[DeviceType.Edge]: 'UA-81915606-9',
|
||||
[DeviceType.Vivaldi]: 'UA-81915606-15',
|
||||
[DeviceType.Safari]: 'UA-81915606-16',
|
||||
};
|
||||
|
||||
export default class BrowserPlatformUtilsService implements Abstractions.PlatformUtilsService {
|
||||
export default class BrowserPlatformUtilsService implements PlatformUtilsService {
|
||||
static getDomain(uriString: string): string {
|
||||
if (uriString == null) {
|
||||
return null;
|
||||
@ -49,56 +51,56 @@ export default class BrowserPlatformUtilsService implements Abstractions.Platfor
|
||||
return ipRegex.test(ipString);
|
||||
}
|
||||
|
||||
private deviceCache: Enums.DeviceType = null;
|
||||
private deviceCache: DeviceType = null;
|
||||
private analyticsIdCache: string = null;
|
||||
|
||||
getDevice(): Enums.DeviceType {
|
||||
getDevice(): DeviceType {
|
||||
if (this.deviceCache) {
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
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 ||
|
||||
navigator.userAgent.indexOf(' OPR/') >= 0) {
|
||||
this.deviceCache = Enums.DeviceType.Opera;
|
||||
this.deviceCache = DeviceType.Opera;
|
||||
} else if (navigator.userAgent.indexOf(' Edge/') !== -1) {
|
||||
this.deviceCache = Enums.DeviceType.Edge;
|
||||
this.deviceCache = DeviceType.Edge;
|
||||
} else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) {
|
||||
this.deviceCache = Enums.DeviceType.Vivaldi;
|
||||
this.deviceCache = DeviceType.Vivaldi;
|
||||
} else if ((window as any).chrome) {
|
||||
this.deviceCache = Enums.DeviceType.Chrome;
|
||||
this.deviceCache = DeviceType.Chrome;
|
||||
}
|
||||
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
getDeviceString(): string {
|
||||
return Enums.DeviceType[this.getDevice()].toLowerCase();
|
||||
return DeviceType[this.getDevice()].toLowerCase();
|
||||
}
|
||||
|
||||
isFirefox(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Firefox;
|
||||
return this.getDevice() === DeviceType.Firefox;
|
||||
}
|
||||
|
||||
isChrome(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Chrome;
|
||||
return this.getDevice() === DeviceType.Chrome;
|
||||
}
|
||||
|
||||
isEdge(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Edge;
|
||||
return this.getDevice() === DeviceType.Edge;
|
||||
}
|
||||
|
||||
isOpera(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Opera;
|
||||
return this.getDevice() === DeviceType.Opera;
|
||||
}
|
||||
|
||||
isVivaldi(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Vivaldi;
|
||||
return this.getDevice() === DeviceType.Vivaldi;
|
||||
}
|
||||
|
||||
isSafari(): boolean {
|
||||
return this.getDevice() === Enums.DeviceType.Safari;
|
||||
return this.getDevice() === DeviceType.Safari;
|
||||
}
|
||||
|
||||
analyticsId(): string {
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import {
|
||||
PlatformUtilsService,
|
||||
StorageService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class BrowserStorageService implements Abstractions.StorageService {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
export default class BrowserStorageService implements StorageService {
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {
|
||||
}
|
||||
|
||||
get<T>(key: string): Promise<T> {
|
||||
|
@ -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 ConstantsService from './constants.service';
|
||||
@ -54,17 +75,17 @@ export default class CipherService {
|
||||
|
||||
decryptedCipherCache: any[];
|
||||
|
||||
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService,
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private settingsService: SettingsService, private apiService: ApiService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
private storageService: StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.decryptedCipherCache = null;
|
||||
}
|
||||
|
||||
async encrypt(model: any): Promise<Domain.Cipher> {
|
||||
const cipher = new Domain.Cipher();
|
||||
async encrypt(model: any): Promise<Cipher> {
|
||||
const cipher = new Cipher();
|
||||
cipher.id = model.id;
|
||||
cipher.folderId = model.folderId;
|
||||
cipher.favorite = model.favorite;
|
||||
@ -87,17 +108,17 @@ export default class CipherService {
|
||||
return cipher;
|
||||
}
|
||||
|
||||
async encryptFields(fieldsModel: any[], key: Domain.SymmetricCryptoKey): Promise<Domain.Field[]> {
|
||||
async encryptFields(fieldsModel: any[], key: SymmetricCryptoKey): Promise<Field[]> {
|
||||
if (!fieldsModel || !fieldsModel.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
const encFields: Domain.Field[] = [];
|
||||
const encFields: Field[] = [];
|
||||
await fieldsModel.reduce((promise, field) => {
|
||||
return promise.then(() => {
|
||||
return self.encryptField(field, key);
|
||||
}).then((encField: Domain.Field) => {
|
||||
}).then((encField: Field) => {
|
||||
encFields.push(encField);
|
||||
});
|
||||
}, Promise.resolve());
|
||||
@ -105,8 +126,8 @@ export default class CipherService {
|
||||
return encFields;
|
||||
}
|
||||
|
||||
async encryptField(fieldModel: any, key: Domain.SymmetricCryptoKey): Promise<Domain.Field> {
|
||||
const field = new Domain.Field();
|
||||
async encryptField(fieldModel: any, key: SymmetricCryptoKey): Promise<Field> {
|
||||
const field = new Field();
|
||||
field.type = fieldModel.type;
|
||||
|
||||
await this.encryptObjProperty(fieldModel, field, {
|
||||
@ -117,27 +138,27 @@ export default class CipherService {
|
||||
return field;
|
||||
}
|
||||
|
||||
async get(id: string): Promise<Domain.Cipher> {
|
||||
async get(id: string): Promise<Cipher> {
|
||||
const userId = await this.userService.getUserId();
|
||||
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);
|
||||
if (ciphers == null || !ciphers.hasOwnProperty(id)) {
|
||||
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 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);
|
||||
const response: Domain.Cipher[] = [];
|
||||
const response: Cipher[] = [];
|
||||
for (const id in ciphers) {
|
||||
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;
|
||||
@ -209,7 +230,7 @@ export default class CipherService {
|
||||
const ciphersToReturn: any[] = [];
|
||||
|
||||
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) {
|
||||
ciphersToReturn.push(cipher);
|
||||
} else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) {
|
||||
@ -272,10 +293,10 @@ export default class CipherService {
|
||||
await this.storageService.save(Keys.neverDomains, domains);
|
||||
}
|
||||
|
||||
async saveWithServer(cipher: Domain.Cipher): Promise<any> {
|
||||
const request = new Request.Cipher(cipher);
|
||||
async saveWithServer(cipher: Cipher): Promise<any> {
|
||||
const request = new CipherRequest(cipher);
|
||||
|
||||
let response: Response.Cipher;
|
||||
let response: CipherResponse;
|
||||
if (cipher.id == null) {
|
||||
response = await this.apiService.postCipher(request);
|
||||
cipher.id = response.id;
|
||||
@ -284,11 +305,11 @@ export default class CipherService {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
saveAttachmentWithServer(cipher: Domain.Cipher, unencryptedFile: any): Promise<any> {
|
||||
saveAttachmentWithServer(cipher: Cipher, unencryptedFile: any): Promise<any> {
|
||||
const self = this;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -304,18 +325,18 @@ export default class CipherService {
|
||||
const blob = new Blob([encData], { type: 'application/octet-stream' });
|
||||
fd.append('data', blob, encFileName.encryptedString);
|
||||
|
||||
let response: Response.Cipher;
|
||||
let response: CipherResponse;
|
||||
try {
|
||||
response = await self.apiService.postCipherAttachment(cipher.id, fd);
|
||||
} catch (e) {
|
||||
reject((e as Response.Error).getSingleMessage());
|
||||
reject((e as ErrorResponse).getSingleMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
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();
|
||||
let ciphers = await this.storageService.get<{ [id: string]: Data.Cipher; }>(
|
||||
let ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
Keys.ciphersPrefix + userId);
|
||||
if (ciphers == null) {
|
||||
ciphers = {};
|
||||
}
|
||||
|
||||
if (cipher instanceof Data.Cipher) {
|
||||
const c = cipher as Data.Cipher;
|
||||
if (cipher instanceof CipherData) {
|
||||
const c = cipher as CipherData;
|
||||
ciphers[c.id] = c;
|
||||
} else {
|
||||
(cipher as Data.Cipher[]).forEach((c) => {
|
||||
(cipher as CipherData[]).forEach((c) => {
|
||||
ciphers[c.id] = c;
|
||||
});
|
||||
}
|
||||
@ -346,7 +367,7 @@ export default class CipherService {
|
||||
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();
|
||||
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
|
||||
this.decryptedCipherCache = null;
|
||||
@ -359,7 +380,7 @@ export default class CipherService {
|
||||
|
||||
async delete(id: string | string[]): Promise<any> {
|
||||
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);
|
||||
if (ciphers == null) {
|
||||
return;
|
||||
@ -385,7 +406,7 @@ export default class CipherService {
|
||||
|
||||
async deleteAttachment(id: string, attachmentId: string): Promise<void> {
|
||||
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);
|
||||
|
||||
if (ciphers == null || !ciphers.hasOwnProperty(id) || ciphers[id].attachments == null) {
|
||||
@ -406,7 +427,7 @@ export default class CipherService {
|
||||
try {
|
||||
await this.apiService.deleteCipherAttachment(id, attachmentId);
|
||||
} catch (e) {
|
||||
return Promise.reject((e as Response.Error).getSingleMessage());
|
||||
return Promise.reject((e as ErrorResponse).getSingleMessage());
|
||||
}
|
||||
await this.deleteAttachment(id, attachmentId);
|
||||
}
|
||||
@ -421,7 +442,7 @@ export default class CipherService {
|
||||
|
||||
// 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 self = this;
|
||||
|
||||
@ -438,7 +459,7 @@ export default class CipherService {
|
||||
return self.cryptoService.encrypt(modelProp, key);
|
||||
}
|
||||
return null;
|
||||
}).then((val: Domain.CipherString) => {
|
||||
}).then((val: CipherString) => {
|
||||
theObj[theProp] = val;
|
||||
});
|
||||
promises.push(p);
|
||||
@ -448,9 +469,9 @@ export default class CipherService {
|
||||
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) {
|
||||
case Enums.CipherType.Login:
|
||||
case CipherType.Login:
|
||||
model.login = {};
|
||||
return this.encryptObjProperty(cipher.login, model.login, {
|
||||
uri: null,
|
||||
@ -458,12 +479,12 @@ export default class CipherService {
|
||||
password: null,
|
||||
totp: null,
|
||||
}, key);
|
||||
case Enums.CipherType.SecureNote:
|
||||
case CipherType.SecureNote:
|
||||
model.secureNote = {
|
||||
type: cipher.secureNote.type,
|
||||
};
|
||||
return Promise.resolve();
|
||||
case Enums.CipherType.Card:
|
||||
case CipherType.Card:
|
||||
model.card = {};
|
||||
return this.encryptObjProperty(cipher.card, model.card, {
|
||||
cardholderName: null,
|
||||
@ -473,7 +494,7 @@ export default class CipherService {
|
||||
expYear: null,
|
||||
code: null,
|
||||
}, key);
|
||||
case Enums.CipherType.Identity:
|
||||
case CipherType.Identity:
|
||||
model.identity = {};
|
||||
return this.encryptObjProperty(cipher.identity, model.identity, {
|
||||
title: null,
|
||||
|
@ -1,6 +1,13 @@
|
||||
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 = {
|
||||
collectionsPrefix: 'collections_',
|
||||
@ -9,33 +16,33 @@ const Keys = {
|
||||
export default class CollectionService {
|
||||
decryptedCollectionCache: any[];
|
||||
|
||||
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private storageService: StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.decryptedCollectionCache = null;
|
||||
}
|
||||
|
||||
async get(id: string): Promise<Domain.Collection> {
|
||||
async get(id: string): Promise<Collection> {
|
||||
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);
|
||||
if (collections == null || !collections.hasOwnProperty(id)) {
|
||||
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 collections = await this.storageService.get<{ [id: string]: Data.Collection; }>(
|
||||
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||
Keys.collectionsPrefix + userId);
|
||||
const response: Domain.Collection[] = [];
|
||||
const response: Collection[] = [];
|
||||
for (const id in collections) {
|
||||
if (collections.hasOwnProperty(id)) {
|
||||
response.push(new Domain.Collection(collections[id]));
|
||||
response.push(new Collection(collections[id]));
|
||||
}
|
||||
}
|
||||
return response;
|
||||
@ -65,19 +72,19 @@ export default class CollectionService {
|
||||
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();
|
||||
let collections = await this.storageService.get<{ [id: string]: Data.Collection; }>(
|
||||
let collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||
Keys.collectionsPrefix + userId);
|
||||
if (collections == null) {
|
||||
collections = {};
|
||||
}
|
||||
|
||||
if (collection instanceof Data.Collection) {
|
||||
const c = collection as Data.Collection;
|
||||
if (collection instanceof CollectionData) {
|
||||
const c = collection as CollectionData;
|
||||
collections[c.id] = c;
|
||||
} else {
|
||||
(collection as Data.Collection[]).forEach((c) => {
|
||||
(collection as CollectionData[]).forEach((c) => {
|
||||
collections[c.id] = c;
|
||||
});
|
||||
}
|
||||
@ -86,7 +93,7 @@ export default class CollectionService {
|
||||
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();
|
||||
await this.storageService.save(Keys.collectionsPrefix + userId, collections);
|
||||
this.decryptedCollectionCache = null;
|
||||
@ -99,7 +106,7 @@ export default class CollectionService {
|
||||
|
||||
async delete(id: string | string[]): Promise<any> {
|
||||
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);
|
||||
if (collections == null) {
|
||||
return;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions';
|
||||
|
||||
export default class ConstantsService {
|
||||
static readonly environmentUrlsKey: string = 'environmentUrls';
|
||||
@ -57,7 +57,7 @@ export default class ConstantsService {
|
||||
|
||||
twoFactorProviderInfo: any[];
|
||||
|
||||
constructor(i18nService: any, platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
constructor(i18nService: any, platformUtilsService: PlatformUtilsService) {
|
||||
if (platformUtilsService.isEdge()) {
|
||||
// delay for i18n fetch
|
||||
setTimeout(() => {
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import {
|
||||
CryptoService,
|
||||
PlatformUtilsService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class ContainerService {
|
||||
constructor(private cryptoService: Abstractions.CryptoService,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
constructor(private cryptoService: CryptoService,
|
||||
private platformUtilsService: PlatformUtilsService) {
|
||||
}
|
||||
|
||||
attachToWindow(win: any) {
|
||||
@ -11,11 +14,11 @@ export default class ContainerService {
|
||||
}
|
||||
}
|
||||
|
||||
getCryptoService(): Abstractions.CryptoService {
|
||||
getCryptoService(): CryptoService {
|
||||
return this.cryptoService;
|
||||
}
|
||||
|
||||
getPlatformUtilsService(): Abstractions.PlatformUtilsService {
|
||||
getPlatformUtilsService(): PlatformUtilsService {
|
||||
return this.platformUtilsService;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
import ApiService from './api.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 {
|
||||
baseUrl: string;
|
||||
@ -10,7 +12,7 @@ export default class EnvironmentService {
|
||||
identityUrl: string;
|
||||
iconsUrl: string;
|
||||
|
||||
constructor(private apiService: ApiService, private storageService: Abstractions.StorageService) {
|
||||
constructor(private apiService: ApiService, private storageService: StorageService) {
|
||||
}
|
||||
|
||||
async setUrlsFromStorage(): Promise<void> {
|
||||
@ -23,7 +25,7 @@ export default class EnvironmentService {
|
||||
webVault: null,
|
||||
};
|
||||
|
||||
const envUrls = new Domain.EnvironmentUrls();
|
||||
const envUrls = new EnvironmentUrls();
|
||||
|
||||
if (urls.base) {
|
||||
this.baseUrl = envUrls.base = urls.base;
|
||||
@ -59,7 +61,7 @@ export default class EnvironmentService {
|
||||
this.identityUrl = urls.identity;
|
||||
this.iconsUrl = urls.icons;
|
||||
|
||||
const envUrls = new Domain.EnvironmentUrls();
|
||||
const envUrls = new EnvironmentUrls();
|
||||
if (this.baseUrl) {
|
||||
envUrls.base = this.baseUrl;
|
||||
} else {
|
||||
|
@ -1,7 +1,18 @@
|
||||
import ApiService from './api.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 = {
|
||||
foldersPrefix: 'folders_',
|
||||
@ -10,41 +21,41 @@ const Keys = {
|
||||
export default class FolderService {
|
||||
decryptedFolderCache: any[];
|
||||
|
||||
constructor(private cryptoService: Abstractions.CryptoService, private userService: UserService,
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private i18nService: any, private apiService: ApiService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
private storageService: StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.decryptedFolderCache = null;
|
||||
}
|
||||
|
||||
async encrypt(model: any): Promise<Domain.Folder> {
|
||||
const folder = new Domain.Folder();
|
||||
async encrypt(model: any): Promise<Folder> {
|
||||
const folder = new Folder();
|
||||
folder.id = model.id;
|
||||
folder.name = await this.cryptoService.encrypt(model.name);
|
||||
return folder;
|
||||
}
|
||||
|
||||
async get(id: string): Promise<Domain.Folder> {
|
||||
async get(id: string): Promise<Folder> {
|
||||
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);
|
||||
if (folders == null || !folders.hasOwnProperty(id)) {
|
||||
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 folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
|
||||
const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
|
||||
Keys.foldersPrefix + userId);
|
||||
const response: Domain.Folder[] = [];
|
||||
const response: Folder[] = [];
|
||||
for (const id in folders) {
|
||||
if (folders.hasOwnProperty(id)) {
|
||||
response.push(new Domain.Folder(folders[id]));
|
||||
response.push(new Folder(folders[id]));
|
||||
}
|
||||
}
|
||||
return response;
|
||||
@ -78,10 +89,10 @@ export default class FolderService {
|
||||
return this.decryptedFolderCache;
|
||||
}
|
||||
|
||||
async saveWithServer(folder: Domain.Folder): Promise<any> {
|
||||
const request = new Request.Folder(folder);
|
||||
async saveWithServer(folder: Folder): Promise<any> {
|
||||
const request = new FolderRequest(folder);
|
||||
|
||||
let response: Response.Folder;
|
||||
let response: FolderResponse;
|
||||
if (folder.id == null) {
|
||||
response = await this.apiService.postFolder(request);
|
||||
folder.id = response.id;
|
||||
@ -90,23 +101,23 @@ export default class FolderService {
|
||||
}
|
||||
|
||||
const userId = await this.userService.getUserId();
|
||||
const data = new Data.Folder(response, userId);
|
||||
const data = new FolderData(response, userId);
|
||||
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();
|
||||
let folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
|
||||
let folders = await this.storageService.get<{ [id: string]: FolderData; }>(
|
||||
Keys.foldersPrefix + userId);
|
||||
if (folders == null) {
|
||||
folders = {};
|
||||
}
|
||||
|
||||
if (folder instanceof Data.Folder) {
|
||||
const f = folder as Data.Folder;
|
||||
if (folder instanceof FolderData) {
|
||||
const f = folder as FolderData;
|
||||
folders[f.id] = f;
|
||||
} else {
|
||||
(folder as Data.Folder[]).forEach((f) => {
|
||||
(folder as FolderData[]).forEach((f) => {
|
||||
folders[f.id] = f;
|
||||
});
|
||||
}
|
||||
@ -115,7 +126,7 @@ export default class FolderService {
|
||||
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();
|
||||
await this.storageService.save(Keys.foldersPrefix + userId, folders);
|
||||
this.decryptedFolderCache = null;
|
||||
@ -128,7 +139,7 @@ export default class FolderService {
|
||||
|
||||
async delete(id: string | string[]): Promise<any> {
|
||||
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);
|
||||
if (folders == null) {
|
||||
return;
|
||||
|
@ -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 = {};
|
||||
|
||||
if (platformUtilsService.isEdge()) {
|
||||
|
@ -3,13 +3,17 @@ import CollectionService from './collection.service';
|
||||
import ConstantsService from './constants.service';
|
||||
import FolderService from './folder.service';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import {
|
||||
CryptoService,
|
||||
PlatformUtilsService,
|
||||
StorageService,
|
||||
} from 'jslib/abstractions';
|
||||
|
||||
export default class LockService {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private cryptoService: Abstractions.CryptoService,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private storageService: Abstractions.StorageService,
|
||||
private collectionService: CollectionService, private cryptoService: CryptoService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private storageService: StorageService,
|
||||
private setIcon: Function, private refreshBadgeAndMenu: Function) {
|
||||
this.checkLock();
|
||||
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds
|
||||
|
@ -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 = {
|
||||
length: 14,
|
||||
@ -75,7 +85,7 @@ export default class PasswordGenerationService {
|
||||
|
||||
// shuffle
|
||||
positions.sort(() => {
|
||||
return Services.UtilsService.secureRandomNumber(0, 1) * 2 - 1;
|
||||
return UtilsService.secureRandomNumber(0, 1) * 2 - 1;
|
||||
});
|
||||
|
||||
// build out the char sets
|
||||
@ -131,7 +141,7 @@ export default class PasswordGenerationService {
|
||||
break;
|
||||
}
|
||||
|
||||
const randomCharIndex = Services.UtilsService.secureRandomNumber(0, positionChars.length - 1);
|
||||
const randomCharIndex = UtilsService.secureRandomNumber(0, positionChars.length - 1);
|
||||
password += positionChars.charAt(randomCharIndex);
|
||||
}
|
||||
|
||||
@ -139,11 +149,11 @@ export default class PasswordGenerationService {
|
||||
}
|
||||
|
||||
optionsCache: any;
|
||||
history: Domain.PasswordHistory[] = [];
|
||||
history: PasswordHistory[] = [];
|
||||
|
||||
constructor(private cryptoService: Abstractions.CryptoService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
storageService.get<Domain.PasswordHistory[]>(Keys.history).then((encrypted) => {
|
||||
constructor(private cryptoService: CryptoService,
|
||||
private storageService: StorageService) {
|
||||
storageService.get<PasswordHistory[]>(Keys.history).then((encrypted) => {
|
||||
return this.decryptHistory(encrypted);
|
||||
}).then((history) => {
|
||||
this.history = history;
|
||||
@ -173,7 +183,7 @@ export default class PasswordGenerationService {
|
||||
}
|
||||
|
||||
getHistory() {
|
||||
return this.history || new Array<Domain.PasswordHistory>();
|
||||
return this.history || new Array<PasswordHistory>();
|
||||
}
|
||||
|
||||
async addHistory(password: string): Promise<any> {
|
||||
@ -182,7 +192,7 @@ export default class PasswordGenerationService {
|
||||
return;
|
||||
}
|
||||
|
||||
this.history.push(new Domain.PasswordHistory(password, Date.now()));
|
||||
this.history.push(new PasswordHistory(password, Date.now()));
|
||||
|
||||
// Remove old items.
|
||||
if (this.history.length > MaxPasswordsInHistory) {
|
||||
@ -198,27 +208,27 @@ export default class PasswordGenerationService {
|
||||
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) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const promises = this.history.map(async (item) => {
|
||||
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);
|
||||
}
|
||||
|
||||
private async decryptHistory(history: Domain.PasswordHistory[]): Promise<Domain.PasswordHistory[]> {
|
||||
private async decryptHistory(history: PasswordHistory[]): Promise<PasswordHistory[]> {
|
||||
if (history == null || history.length === 0) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const promises = history.map(async (item) => {
|
||||
const decrypted = await this.cryptoService.decrypt(new Domain.CipherString(item.password));
|
||||
return new Domain.PasswordHistory(decrypted, item.date);
|
||||
const decrypted = await this.cryptoService.decrypt(new CipherString(item.password));
|
||||
return new PasswordHistory(decrypted, item.date);
|
||||
});
|
||||
|
||||
return await Promise.all(promises);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import UserService from './user.service';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
const Keys = {
|
||||
settingsPrefix: 'settings_',
|
||||
@ -10,7 +10,7 @@ const Keys = {
|
||||
export default class SettingsService {
|
||||
private settingsCache: any;
|
||||
|
||||
constructor(private userService: UserService, private storageService: Abstractions.StorageService) {
|
||||
constructor(private userService: UserService, private storageService: StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
|
@ -5,7 +5,25 @@ import FolderService from './folder.service';
|
||||
import SettingsService from './settings.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 = {
|
||||
lastSyncPrefix: 'lastSync_',
|
||||
@ -16,9 +34,9 @@ export default class SyncService {
|
||||
|
||||
constructor(private userService: UserService, private apiService: ApiService,
|
||||
private settingsService: SettingsService, private folderService: FolderService,
|
||||
private cipherService: CipherService, private cryptoService: Abstractions.CryptoService,
|
||||
private collectionService: CollectionService, private storageService: Abstractions.StorageService,
|
||||
private messagingService: Abstractions.MessagingService, private logoutCallback: Function) {
|
||||
private cipherService: CipherService, private cryptoService: CryptoService,
|
||||
private collectionService: CollectionService, private storageService: StorageService,
|
||||
private messagingService: MessagingService, private logoutCallback: Function) {
|
||||
}
|
||||
|
||||
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();
|
||||
if (stamp != null && stamp !== response.securityStamp) {
|
||||
if (this.logoutCallback != null) {
|
||||
@ -126,31 +144,31 @@ export default class SyncService {
|
||||
await this.userService.setSecurityStamp(response.securityStamp);
|
||||
}
|
||||
|
||||
private async syncFolders(userId: string, response: Response.Folder[]) {
|
||||
const folders: { [id: string]: Data.Folder; } = {};
|
||||
private async syncFolders(userId: string, response: FolderResponse[]) {
|
||||
const folders: { [id: string]: FolderData; } = {};
|
||||
response.forEach((f) => {
|
||||
folders[f.id] = new Data.Folder(f, userId);
|
||||
folders[f.id] = new FolderData(f, userId);
|
||||
});
|
||||
return await this.folderService.replace(folders);
|
||||
}
|
||||
|
||||
private async syncCollections(response: Response.Collection[]) {
|
||||
const collections: { [id: string]: Data.Collection; } = {};
|
||||
private async syncCollections(response: CollectionResponse[]) {
|
||||
const collections: { [id: string]: CollectionData; } = {};
|
||||
response.forEach((c) => {
|
||||
collections[c.id] = new Data.Collection(c);
|
||||
collections[c.id] = new CollectionData(c);
|
||||
});
|
||||
return await this.collectionService.replace(collections);
|
||||
}
|
||||
|
||||
private async syncCiphers(userId: string, response: Response.Cipher[]) {
|
||||
const ciphers: { [id: string]: Data.Cipher; } = {};
|
||||
private async syncCiphers(userId: string, response: CipherResponse[]) {
|
||||
const ciphers: { [id: string]: CipherData; } = {};
|
||||
response.forEach((c) => {
|
||||
ciphers[c.id] = new Data.Cipher(c, userId);
|
||||
ciphers[c.id] = new CipherData(c, userId);
|
||||
});
|
||||
return await this.cipherService.replace(ciphers);
|
||||
}
|
||||
|
||||
private async syncSettings(userId: string, response: Response.Domains) {
|
||||
private async syncSettings(userId: string, response: DomainsResponse) {
|
||||
let eqDomains: string[][] = [];
|
||||
if (response != null && response.equivalentDomains != null) {
|
||||
eqDomains = eqDomains.concat(response.equivalentDomains);
|
||||
|
@ -1,6 +1,8 @@
|
||||
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 = {
|
||||
accessToken: 'accessToken',
|
||||
@ -13,7 +15,7 @@ export default class TokenService {
|
||||
decodedToken: any;
|
||||
refreshToken: string;
|
||||
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
constructor(private storageService: StorageService) {
|
||||
}
|
||||
|
||||
setTokens(accessToken: string, refreshToken: string): Promise<any> {
|
||||
@ -92,7 +94,7 @@ export default class TokenService {
|
||||
throw new Error('JWT must have 3 parts');
|
||||
}
|
||||
|
||||
const decoded = Services.UtilsService.urlBase64Decode(parts[1]);
|
||||
const decoded = UtilsService.urlBase64Decode(parts[1]);
|
||||
if (decoded == null) {
|
||||
throw new Error('Cannot decode the token');
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import ConstantsService from './constants.service';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
const b32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||
|
||||
@ -10,7 +10,7 @@ const TotpAlgorithm = {
|
||||
};
|
||||
|
||||
export default class TotpService {
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
constructor(private storageService: StorageService) {
|
||||
}
|
||||
|
||||
async getCode(keyb32: string): Promise<string> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import TokenService from './token.service';
|
||||
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
import { StorageService } from 'jslib/abstractions';
|
||||
|
||||
const Keys = {
|
||||
userId: 'userId',
|
||||
@ -13,7 +13,7 @@ export default class UserService {
|
||||
email: 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> {
|
||||
|
@ -1,32 +1,32 @@
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
import { UtilsService } from 'jslib/services';
|
||||
|
||||
describe('Utils Service', () => {
|
||||
describe('getHostname', () => {
|
||||
it('should fail for invalid urls', () => {
|
||||
expect(Services.UtilsService.getHostname(null)).toBeNull();
|
||||
expect(Services.UtilsService.getHostname(undefined)).toBeNull();
|
||||
expect(Services.UtilsService.getHostname(' ')).toBeNull();
|
||||
expect(Services.UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
|
||||
expect(Services.UtilsService.getHostname('bitwarden')).toBeNull();
|
||||
expect(UtilsService.getHostname(null)).toBeNull();
|
||||
expect(UtilsService.getHostname(undefined)).toBeNull();
|
||||
expect(UtilsService.getHostname(' ')).toBeNull();
|
||||
expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
|
||||
expect(UtilsService.getHostname('bitwarden')).toBeNull();
|
||||
});
|
||||
|
||||
it('should handle valid urls', () => {
|
||||
expect(Services.UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(Services.UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(Services.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://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.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', () => {
|
||||
expect(Services.UtilsService.getHostname('https://localhost')).toBe('localhost');
|
||||
expect(Services.UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||
expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
|
||||
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newGuid', () => {
|
||||
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;
|
||||
expect(Services.UtilsService.newGuid()).toMatch(validGuid);
|
||||
expect(UtilsService.newGuid()).toMatch(validGuid);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -8,7 +8,11 @@
|
||||
"sourceMap": true,
|
||||
"types": [
|
||||
"jasmine"
|
||||
]
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"jslib/*": [ "node_modules/@bitwarden/jslib/src/*" ]
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
|
@ -103,7 +103,10 @@ module.exports = {
|
||||
])
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js']
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
alias: {
|
||||
jslib: path.join(__dirname, 'node_modules/@bitwarden/jslib/src')
|
||||
}
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
|
Loading…
Reference in New Issue
Block a user