2018-05-12 21:12:28 +02:00
|
|
|
import { AuthService } from 'jslib/services/auth.service';
|
|
|
|
|
2018-05-15 05:40:11 +02:00
|
|
|
import { I18nService } from './services/i18n.service';
|
2018-05-16 03:11:58 +02:00
|
|
|
import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { NodeMessagingService } from './services/nodeMessaging.service';
|
|
|
|
import { NodePlatformUtilsService } from './services/nodePlatformUtils.service';
|
2018-05-13 06:19:14 +02:00
|
|
|
import { NodeStorageService } from './services/nodeStorage.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
|
2018-05-13 06:19:14 +02:00
|
|
|
import { AppIdService } from 'jslib/services/appId.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { AuditService } from 'jslib/services/audit.service';
|
2018-05-14 17:15:54 +02:00
|
|
|
import { CipherService } from 'jslib/services/cipher.service';
|
|
|
|
import { CollectionService } from 'jslib/services/collection.service';
|
|
|
|
import { ConstantsService } from 'jslib/services/constants.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { ContainerService } from 'jslib/services/container.service';
|
|
|
|
import { CryptoService } from 'jslib/services/crypto.service';
|
|
|
|
import { EnvironmentService } from 'jslib/services/environment.service';
|
|
|
|
import { FolderService } from 'jslib/services/folder.service';
|
|
|
|
import { LockService } from 'jslib/services/lock.service';
|
2018-05-15 05:57:02 +02:00
|
|
|
import { NodeApiService } from 'jslib/services/nodeApi.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { NodeCryptoFunctionService } from 'jslib/services/nodeCryptoFunction.service';
|
2018-05-14 17:15:54 +02:00
|
|
|
import { PasswordGenerationService } from 'jslib/services/passwordGeneration.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { SettingsService } from 'jslib/services/settings.service';
|
|
|
|
import { SyncService } from 'jslib/services/sync.service';
|
|
|
|
import { TokenService } from 'jslib/services/token.service';
|
2018-05-14 17:15:54 +02:00
|
|
|
import { TotpService } from 'jslib/services/totp.service';
|
2018-05-15 05:40:11 +02:00
|
|
|
import { UserService } from 'jslib/services/user.service';
|
2018-05-13 06:19:14 +02:00
|
|
|
|
2018-05-14 17:15:54 +02:00
|
|
|
import { Program } from './program';
|
2018-05-13 06:19:14 +02:00
|
|
|
|
2018-05-14 17:15:54 +02:00
|
|
|
export class Main {
|
|
|
|
messagingService: NodeMessagingService;
|
|
|
|
storageService: NodeStorageService;
|
|
|
|
secureStorageService: NodeStorageService;
|
|
|
|
i18nService: I18nService;
|
|
|
|
platformUtilsService: NodePlatformUtilsService;
|
|
|
|
constantsService: ConstantsService;
|
|
|
|
cryptoService: CryptoService;
|
|
|
|
tokenService: TokenService;
|
|
|
|
appIdService: AppIdService;
|
2018-05-15 05:57:02 +02:00
|
|
|
apiService: NodeApiService;
|
2018-05-14 17:15:54 +02:00
|
|
|
environmentService: EnvironmentService;
|
|
|
|
userService: UserService;
|
|
|
|
settingsService: SettingsService;
|
|
|
|
cipherService: CipherService;
|
|
|
|
folderService: FolderService;
|
|
|
|
collectionService: CollectionService;
|
|
|
|
lockService: LockService;
|
|
|
|
syncService: SyncService;
|
|
|
|
passwordGenerationService: PasswordGenerationService;
|
|
|
|
totpService: TotpService;
|
|
|
|
containerService: ContainerService;
|
|
|
|
auditService: AuditService;
|
|
|
|
cryptoFunctionService: NodeCryptoFunctionService;
|
|
|
|
authService: AuthService;
|
|
|
|
program: Program;
|
2018-05-11 19:47:18 +02:00
|
|
|
|
2018-05-14 17:15:54 +02:00
|
|
|
constructor() {
|
2018-05-15 05:16:59 +02:00
|
|
|
this.i18nService = new I18nService('en', './locales');
|
2018-05-14 17:15:54 +02:00
|
|
|
this.platformUtilsService = new NodePlatformUtilsService();
|
|
|
|
this.cryptoFunctionService = new NodeCryptoFunctionService();
|
|
|
|
this.storageService = new NodeStorageService('Bitwarden CLI');
|
2018-05-16 03:11:58 +02:00
|
|
|
this.secureStorageService = new NodeEnvSecureStorageService(this.storageService, () => this.cryptoService);
|
|
|
|
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService,
|
|
|
|
this.cryptoFunctionService);
|
2018-05-14 17:15:54 +02:00
|
|
|
this.appIdService = new AppIdService(this.storageService);
|
|
|
|
this.tokenService = new TokenService(this.storageService);
|
|
|
|
this.messagingService = new NodeMessagingService();
|
2018-05-15 05:57:02 +02:00
|
|
|
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService,
|
2018-05-15 05:40:11 +02:00
|
|
|
(expired: boolean) => { /* do nothing */ });
|
2018-05-14 17:15:54 +02:00
|
|
|
this.environmentService = new EnvironmentService(this.apiService, this.storageService);
|
|
|
|
this.userService = new UserService(this.tokenService, this.storageService);
|
|
|
|
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
|
|
|
|
this.settingsService = new SettingsService(this.userService, this.storageService);
|
|
|
|
this.cipherService = new CipherService(this.cryptoService, this.userService, this.settingsService,
|
|
|
|
this.apiService, this.storageService, this.i18nService, this.platformUtilsService);
|
|
|
|
this.folderService = new FolderService(this.cryptoService, this.userService,
|
|
|
|
() => 'No Folder', this.apiService, this.storageService, this.i18nService);
|
|
|
|
this.collectionService = new CollectionService(this.cryptoService, this.userService, this.storageService,
|
|
|
|
this.i18nService);
|
|
|
|
this.lockService = new LockService(this.cipherService, this.folderService, this.collectionService,
|
|
|
|
this.cryptoService, this.platformUtilsService, this.storageService, this.messagingService,
|
|
|
|
() => { /* do nothing */ });
|
|
|
|
this.syncService = new SyncService(this.userService, this.apiService, this.settingsService,
|
|
|
|
this.folderService, this.cipherService, this.cryptoService, this.collectionService,
|
2018-05-15 05:40:11 +02:00
|
|
|
this.storageService, this.messagingService, (expired: boolean) => { /* do nothing */ });
|
2018-05-14 19:37:52 +02:00
|
|
|
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
|
|
|
|
this.totpService = new TotpService(this.storageService, this.cryptoFunctionService);
|
2018-05-14 17:15:54 +02:00
|
|
|
this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService,
|
|
|
|
this.appIdService, this.i18nService, this.platformUtilsService, this.messagingService, true);
|
|
|
|
this.program = new Program(this);
|
|
|
|
}
|
2018-05-11 19:47:18 +02:00
|
|
|
|
2018-05-15 05:16:59 +02:00
|
|
|
async run() {
|
|
|
|
await this.init();
|
|
|
|
this.program.run();
|
|
|
|
}
|
|
|
|
|
2018-05-14 17:15:54 +02:00
|
|
|
private async init() {
|
|
|
|
this.containerService.attachToWindow(global);
|
|
|
|
await this.environmentService.setUrlsFromStorage();
|
|
|
|
const locale = await this.storageService.get<string>(ConstantsService.localeKey);
|
|
|
|
await this.i18nService.init(locale);
|
|
|
|
await this.authService.init();
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 17:59:34 +02:00
|
|
|
|
2018-05-15 05:16:59 +02:00
|
|
|
const main = new Main();
|
|
|
|
main.run();
|