From 4ec06bbd1ef8448c3a0511c9c221063b90fd3aae Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 23 Jul 2021 22:46:32 +0200 Subject: [PATCH] Add support for helpers in environment service (#353) --- jslib | 2 +- package-lock.json | 1 + package.json | 1 + src/bw.ts | 4 ++-- src/commands/config.command.ts | 5 +++-- src/commands/send/receive.command.ts | 7 ++++--- src/commands/status.command.ts | 6 +----- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/jslib b/jslib index 18bf616e2e..ecdd08624f 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 18bf616e2e0821a46b1cb71737d80b099a64b237 +Subproject commit ecdd08624f61ccff8128b7cb3241f39e664e1c7f diff --git a/package-lock.json b/package-lock.json index 71134d6ea8..2f71857618 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,6 +23,7 @@ "node-forge": "0.10.0", "open": "^8.0.8", "papaparse": "^5.3.0", + "rxjs": "6.6.7", "tldjs": "^2.3.1", "zxcvbn": "^4.4.2" }, diff --git a/package.json b/package.json index 3764c3d0f1..9787dfa90d 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "node-forge": "0.10.0", "open": "^8.0.8", "papaparse": "^5.3.0", + "rxjs": "6.6.7", "tldjs": "^2.3.1", "zxcvbn": "^4.4.2" }, diff --git a/src/bw.ts b/src/bw.ts index 175ea736c7..b3c84110d8 100644 --- a/src/bw.ts +++ b/src/bw.ts @@ -116,11 +116,11 @@ export class Main { this.appIdService = new AppIdService(this.storageService); this.tokenService = new TokenService(this.storageService); this.messagingService = new NoopMessagingService(); - this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, + this.environmentService = new EnvironmentService(this.storageService); + this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, this.environmentService, async (expired: boolean) => await this.logout(), 'Bitwarden_CLI/' + this.platformUtilsService.getApplicationVersion() + ' (' + this.platformUtilsService.getDeviceString().toUpperCase() + ')'); - this.environmentService = new EnvironmentService(this.apiService, this.storageService, null); this.userService = new UserService(this.tokenService, this.storageService); this.containerService = new ContainerService(this.cryptoService); this.settingsService = new SettingsService(this.userService, this.storageService); diff --git a/src/commands/config.command.ts b/src/commands/config.command.ts index fdac3a1400..4806550e73 100644 --- a/src/commands/config.command.ts +++ b/src/commands/config.command.ts @@ -23,8 +23,9 @@ export class ConfigCommand { private async getOrSetServer(url: string, options: program.OptionValues): Promise { if ((url == null || url.trim() === '') && !options.webVault && !options.api && !options.identity && !options.icons && !options.notifications && !options.events) { - const baseUrl = this.environmentService.baseUrl; - const stringRes = new StringResponse(baseUrl == null ? 'https://bitwarden.com' : baseUrl); + const stringRes = new StringResponse( + this.environmentService.hasBaseUrl() ? this.environmentService.getUrls().base : 'https://bitwarden.com' + ); return Response.success(stringRes); } diff --git a/src/commands/send/receive.command.ts b/src/commands/send/receive.command.ts index cf424f7792..fc508ba903 100644 --- a/src/commands/send/receive.command.ts +++ b/src/commands/send/receive.command.ts @@ -99,12 +99,13 @@ export class SendReceiveCommand extends DownloadCommand { } private getApiUrl(url: URL) { + const urls = this.environmentService.getUrls(); if (url.origin === 'https://send.bitwarden.com') { return 'https://vault.bitwarden.com/api'; - } else if (url.origin === this.apiService.apiBaseUrl) { + } else if (url.origin === urls.api) { return url.origin; - } else if (this.platformUtilsService.isDev() && url.origin === this.environmentService.getWebVaultUrl()) { - return this.apiService.apiBaseUrl; + } else if (this.platformUtilsService.isDev() && url.origin === urls.webVault) { + return urls.api; } else { return url.origin + '/api'; } diff --git a/src/commands/status.command.ts b/src/commands/status.command.ts index 9260e08a18..5ffe98d343 100644 --- a/src/commands/status.command.ts +++ b/src/commands/status.command.ts @@ -35,11 +35,7 @@ export class StatusCommand { } private baseUrl(): string { - let url = this.envService.baseUrl; - if (url == null) { - url = 'https://bitwarden.com'; - } - return url; + return this.envService.getUrls().base; } private async status(): Promise {