1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

Ps/pm 5965/better config polling (#8325)

* Create tracker that can await until expected observables are received.

* Test dates are almost equal

* Remove unused class method

* Allow for updating active account in accout service fake

* Correct observable tracker behavior

Clarify documentation

* Transition config service to state provider

Updates the config fetching behavior to be lazy and ensure that any emitted value has been updated if older than a configurable value (statically compiled).

If desired, config fetching can be ensured fresh through an async.

* Update calls to config service in DI and bootstrapping

* Migrate account server configs

* Fix global config fetching

* Test migration rollback

* Adhere to implementation naming convention

* Adhere to abstract class naming convention

* Complete config abstraction rename

* Remove unnecessary cli config service

* Fix builds

* Validate observable does not complete

* Use token service to determine authed or unauthed config pull

* Remove superfluous factory config

* Name describe blocks after the thing they test

* Remove implementation documentation

Unfortunately the experience when linking to external documentation is quite poor. Instead of following the link and retrieving docs, you get a link that can be clicked to take you out of context to the docs. No link _does_ retrieve docs, but lacks indication in the implementation that documentation exists at all.

On the balance, removing the link is the better experience.

* Fix storybook
This commit is contained in:
Matt Gibson
2024-03-27 12:03:09 -05:00
committed by GitHub
parent 64d6f6fef3
commit 62ad39e697
79 changed files with 946 additions and 609 deletions

View File

@@ -12,7 +12,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@@ -44,7 +44,7 @@ export class SsoComponent extends BaseSsoComponent {
environmentService: EnvironmentService,
logService: LogService,
userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
configService: ConfigServiceAbstraction,
configService: ConfigService,
protected authService: AuthService,
@Inject(WINDOW) private win: Window,
) {

View File

@@ -16,7 +16,7 @@ import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor
import { TwoFactorProviderType } from "@bitwarden/common/auth/enums/two-factor-provider-type";
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
@@ -59,7 +59,7 @@ export class TwoFactorComponent extends BaseTwoFactorComponent {
appIdService: AppIdService,
loginService: LoginService,
userDecryptionOptionsService: UserDecryptionOptionsServiceAbstraction,
configService: ConfigServiceAbstraction,
configService: ConfigService,
ssoLoginService: SsoLoginServiceAbstraction,
private dialogService: DialogService,
@Inject(WINDOW) protected win: Window,

View File

@@ -70,6 +70,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
import { DefaultBillingAccountProfileStateService } from "@bitwarden/common/billing/services/account/billing-account-profile-state.service";
import { AppIdService as AppIdServiceAbstraction } from "@bitwarden/common/platform/abstractions/app-id.service";
import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config-api.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
@@ -93,6 +94,7 @@ import { StateFactory } from "@bitwarden/common/platform/factories/state-factory
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation";
@@ -201,7 +203,6 @@ import { BrowserApi } from "../platform/browser/browser-api";
import { flagEnabled } from "../platform/flags";
import { UpdateBadge } from "../platform/listeners/update-badge";
import { BrowserStateService as StateServiceAbstraction } from "../platform/services/abstractions/browser-state.service";
import { BrowserConfigService } from "../platform/services/browser-config.service";
import { BrowserCryptoService } from "../platform/services/browser-crypto.service";
import { BrowserEnvironmentService } from "../platform/services/browser-environment.service";
import BrowserLocalStorageService from "../platform/services/browser-local-storage.service";
@@ -293,7 +294,7 @@ export default class MainBackground {
avatarService: AvatarServiceAbstraction;
mainContextMenuHandler: MainContextMenuHandler;
cipherContextMenuHandler: CipherContextMenuHandler;
configService: BrowserConfigService;
configService: ConfigService;
configApiService: ConfigApiServiceAbstraction;
devicesApiService: DevicesApiServiceAbstraction;
devicesService: DevicesServiceAbstraction;
@@ -609,16 +610,13 @@ export default class MainBackground {
this.userVerificationApiService = new UserVerificationApiService(this.apiService);
this.configApiService = new ConfigApiService(this.apiService, this.authService);
this.configApiService = new ConfigApiService(this.apiService, this.tokenService);
this.configService = new BrowserConfigService(
this.stateService,
this.configService = new DefaultConfigService(
this.configApiService,
this.authService,
this.environmentService,
this.logService,
this.stateProvider,
true,
);
this.cipherService = new CipherService(
@@ -1005,7 +1003,6 @@ export default class MainBackground {
this.filelessImporterBackground.init();
await this.commandsBackground.init();
this.configService.init();
this.twoFactorService.init();
await this.overlayBackground.init();

View File

@@ -3,7 +3,7 @@ import { firstValueFrom } from "rxjs";
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
@@ -46,7 +46,7 @@ export default class RuntimeBackground {
private environmentService: BrowserEnvironmentService,
private messagingService: MessagingService,
private logService: LogService,
private configService: ConfigServiceAbstraction,
private configService: ConfigService,
private fido2Service: Fido2Service,
) {
// onInstalled listener must be wired up before anything else, so we do it in the ctor
@@ -136,7 +136,7 @@ export default class RuntimeBackground {
await this.main.refreshBadge();
await this.main.refreshMenu();
}, 2000);
this.configService.triggerServerConfigFetch();
await this.configService.ensureConfigFetched();
}
break;
case "openPopup":

View File

@@ -2,9 +2,9 @@ import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstract
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
import {
authServiceFactory,
AuthServiceInitOptions,
} from "../../../auth/background/service-factories/auth-service.factory";
tokenServiceFactory,
TokenServiceInitOptions,
} from "../../../auth/background/service-factories/token-service.factory";
import { apiServiceFactory, ApiServiceInitOptions } from "./api-service.factory";
import { FactoryOptions, CachedServices, factory } from "./factory-options";
@@ -13,7 +13,7 @@ type ConfigApiServiceFactoyOptions = FactoryOptions;
export type ConfigApiServiceInitOptions = ConfigApiServiceFactoyOptions &
ApiServiceInitOptions &
AuthServiceInitOptions;
TokenServiceInitOptions;
export function configApiServiceFactory(
cache: { configApiService?: ConfigApiServiceAbstraction } & CachedServices,
@@ -26,7 +26,7 @@ export function configApiServiceFactory(
async () =>
new ConfigApiService(
await apiServiceFactory(cache, opts),
await authServiceFactory(cache, opts),
await tokenServiceFactory(cache, opts),
),
);
}

View File

@@ -1,10 +1,5 @@
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/services/config/config.service";
import {
authServiceFactory,
AuthServiceInitOptions,
} from "../../../auth/background/service-factories/auth-service.factory";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
import { configApiServiceFactory, ConfigApiServiceInitOptions } from "./config-api.service.factory";
import {
@@ -13,39 +8,30 @@ import {
} from "./environment-service.factory";
import { FactoryOptions, CachedServices, factory } from "./factory-options";
import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory";
import { stateProviderFactory } from "./state-provider.factory";
import { stateServiceFactory, StateServiceInitOptions } from "./state-service.factory";
import { stateProviderFactory, StateProviderInitOptions } from "./state-provider.factory";
type ConfigServiceFactoryOptions = FactoryOptions & {
configServiceOptions?: {
subscribe?: boolean;
};
};
type ConfigServiceFactoryOptions = FactoryOptions;
export type ConfigServiceInitOptions = ConfigServiceFactoryOptions &
StateServiceInitOptions &
ConfigApiServiceInitOptions &
AuthServiceInitOptions &
EnvironmentServiceInitOptions &
LogServiceInitOptions;
LogServiceInitOptions &
StateProviderInitOptions;
export function configServiceFactory(
cache: { configService?: ConfigServiceAbstraction } & CachedServices,
cache: { configService?: ConfigService } & CachedServices,
opts: ConfigServiceInitOptions,
): Promise<ConfigServiceAbstraction> {
): Promise<ConfigService> {
return factory(
cache,
"configService",
opts,
async () =>
new ConfigService(
await stateServiceFactory(cache, opts),
new DefaultConfigService(
await configApiServiceFactory(cache, opts),
await authServiceFactory(cache, opts),
await environmentServiceFactory(cache, opts),
await logServiceFactory(cache, opts),
await stateProviderFactory(cache, opts),
opts.configServiceOptions?.subscribe ?? true,
),
);
}

View File

@@ -1,38 +0,0 @@
import { ReplaySubject } from "rxjs";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config-api.service.abstraction";
import { ServerConfig } from "@bitwarden/common/platform/abstractions/config/server-config";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { ConfigService } from "@bitwarden/common/platform/services/config/config.service";
import { StateProvider } from "@bitwarden/common/platform/state";
import { browserSession, sessionSync } from "../decorators/session-sync-observable";
@browserSession
export class BrowserConfigService extends ConfigService {
@sessionSync<ServerConfig>({ initializer: ServerConfig.fromJSON })
protected _serverConfig: ReplaySubject<ServerConfig | null>;
constructor(
stateService: StateService,
configApiService: ConfigApiServiceAbstraction,
authService: AuthService,
environmentService: EnvironmentService,
logService: LogService,
stateProvider: StateProvider,
subscribe = false,
) {
super(
stateService,
configApiService,
authService,
environmentService,
logService,
stateProvider,
subscribe,
);
}
}

View File

@@ -5,7 +5,6 @@ import { AbstractThemingService } from "@bitwarden/angular/platform/services/the
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService as LogServiceAbstraction } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ConfigService } from "@bitwarden/common/platform/services/config/config.service";
import { BrowserApi } from "../../platform/browser/browser-api";
import BrowserPopupUtils from "../../platform/popup/browser-popup-utils";
@@ -19,7 +18,6 @@ export class InitService {
private stateService: StateServiceAbstraction,
private logService: LogServiceAbstraction,
private themingService: AbstractThemingService,
private configService: ConfigService,
@Inject(DOCUMENT) private document: Document,
) {}
@@ -55,7 +53,6 @@ export class InitService {
this.logService.info("Force redraw is on");
}
this.configService.init();
this.setupVaultPopupHeartbeat();
};
}

View File

@@ -46,17 +46,13 @@ import {
UserNotificationSettingsService,
UserNotificationSettingsServiceAbstraction,
} from "@bitwarden/common/autofill/services/user-notification-settings.service";
import { ConfigApiServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config-api.service.abstraction";
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service";
import {
LogService,
LogService as LogServiceAbstraction,
} from "@bitwarden/common/platform/abstractions/log.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
@@ -66,7 +62,6 @@ import {
} from "@bitwarden/common/platform/abstractions/storage.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { ConfigService } from "@bitwarden/common/platform/services/config/config.service";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
@@ -95,7 +90,6 @@ import { Account } from "../../models/account";
import { BrowserApi } from "../../platform/browser/browser-api";
import BrowserPopupUtils from "../../platform/popup/browser-popup-utils";
import { BrowserStateService as StateServiceAbstraction } from "../../platform/services/abstractions/browser-state.service";
import { BrowserConfigService } from "../../platform/services/browser-config.service";
import { BrowserEnvironmentService } from "../../platform/services/browser-environment.service";
import { BrowserFileDownloadService } from "../../platform/services/browser-file-download.service";
import BrowserLocalStorageService from "../../platform/services/browser-local-storage.service";
@@ -186,7 +180,7 @@ function getBgService<T>(service: keyof MainBackground) {
i18nService,
);
},
deps: [LogServiceAbstraction, I18nServiceAbstraction],
deps: [LogService, I18nServiceAbstraction],
},
{
provide: CipherFileUploadService,
@@ -205,7 +199,7 @@ function getBgService<T>(service: keyof MainBackground) {
deps: [],
},
{
provide: LogServiceAbstraction,
provide: LogService,
useFactory: (platformUtilsService: PlatformUtilsService) =>
new ConsoleLogService(platformUtilsService.isDev()),
deps: [PlatformUtilsService],
@@ -367,7 +361,7 @@ function getBgService<T>(service: keyof MainBackground) {
storageService: AbstractStorageService,
secureStorageService: AbstractStorageService,
memoryStorageService: AbstractMemoryStorageService,
logService: LogServiceAbstraction,
logService: LogService,
accountService: AccountServiceAbstraction,
environmentService: EnvironmentService,
tokenService: TokenService,
@@ -389,7 +383,7 @@ function getBgService<T>(service: keyof MainBackground) {
AbstractStorageService,
SECURE_STORAGE,
MEMORY_STORAGE,
LogServiceAbstraction,
LogService,
AccountServiceAbstraction,
EnvironmentService,
TokenService,
@@ -430,18 +424,6 @@ function getBgService<T>(service: keyof MainBackground) {
},
deps: [PlatformUtilsService],
},
{
provide: ConfigService,
useClass: BrowserConfigService,
deps: [
StateServiceAbstraction,
ConfigApiServiceAbstraction,
AuthServiceAbstraction,
EnvironmentService,
StateProvider,
LogService,
],
},
{
provide: FilePopoutUtilsService,
useFactory: (platformUtilsService: PlatformUtilsService) => {

View File

@@ -3,7 +3,7 @@ import { Component } from "@angular/core";
import { combineLatest, map } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { ButtonModule, DialogModule } from "@bitwarden/components";
@@ -24,7 +24,7 @@ export class AboutComponent {
]).pipe(map(([serverConfig, isCloud]) => ({ serverConfig, isCloud })));
constructor(
private configService: ConfigServiceAbstraction,
private configService: ConfigService,
private environmentService: EnvironmentService,
) {}
}

View File

@@ -4,7 +4,7 @@ import { firstValueFrom } from "rxjs";
import { PolicyService } from "@bitwarden/common/admin-console/services/policy/policy.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
import { ConfigService } from "@bitwarden/common/platform/services/config/config.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { Importer, ImportResult, ImportServiceAbstraction } from "@bitwarden/importer/core";

View File

@@ -5,7 +5,7 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { ImportServiceAbstraction } from "@bitwarden/importer/core";
@@ -55,7 +55,7 @@ class FilelessImporterBackground implements FilelessImporterBackgroundInterface
* @param syncService - Used to trigger a full sync after the import is completed.
*/
constructor(
private configService: ConfigServiceAbstraction,
private configService: ConfigService,
private authService: AuthService,
private policyService: PolicyService,
private notificationBackground: NotificationBackground,

View File

@@ -11,7 +11,7 @@ import { EventCollectionService } from "@bitwarden/common/abstractions/event/eve
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { ConfigServiceAbstraction } from "@bitwarden/common/platform/abstractions/config/config.service.abstraction";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
@@ -68,7 +68,7 @@ export class AddEditComponent extends BaseAddEditComponent {
sendApiService: SendApiService,
dialogService: DialogService,
datePipe: DatePipe,
configService: ConfigServiceAbstraction,
configService: ConfigService,
) {
super(
cipherService,