diff --git a/libs/common/src/tools/providers.ts b/libs/common/src/tools/providers.ts index e327391da3c..b83c36e36af 100644 --- a/libs/common/src/tools/providers.ts +++ b/libs/common/src/tools/providers.ts @@ -1,10 +1,14 @@ +import { SemVer } from "semver"; + import { LogService, LogProvider } from "@bitwarden/logging"; import { BitwardenClient } from "@bitwarden/sdk-internal"; import { StateProvider } from "@bitwarden/state"; import { PolicyService } from "../admin-console/abstractions/policy/policy.service.abstraction"; +import { FeatureFlag } from "../enums/feature-flag.enum"; import { ConfigService } from "../platform/abstractions/config/config.service"; import { PlatformUtilsService } from "../platform/abstractions/platform-utils.service"; +import { UserId } from "../types/guid"; import { LegacyEncryptorProvider } from "./cryptography/legacy-encryptor-provider"; import { ExtensionRegistry } from "./extension/extension-registry.abstraction"; @@ -64,3 +68,139 @@ export function createSystemServiceProvider( environment, }; } + +/** + * Facade exposing methods from ConfigService and PlatformUtilsService that appear related to environmental awareness + */ +export class EnvService { + constructor( + private configService: ConfigService, + private platformUtilsService: PlatformUtilsService, + ) {} + + /* ConfigService methods */ + get serverConfig$() { + return this.configService.serverConfig$; + } + + get serverSettings$() { + return this.configService.serverSettings$; + } + + get cloudRegion$() { + return this.configService.cloudRegion$; + } + + getFeatureFlag$(key: Flag) { + return this.configService.getFeatureFlag$(key); + } + + userCachedFeatureFlag$(key: Flag, userId: UserId) { + return this.configService.userCachedFeatureFlag$(key, userId); + } + + getFeatureFlag(key: Flag) { + return this.configService.getFeatureFlag(key); + } + + checkServerMeetsVersionRequirement$(minimumRequiredServerVersion: SemVer) { + return this.configService.checkServerMeetsVersionRequirement$(minimumRequiredServerVersion); + } + + ensureConfigFetched() { + return this.configService.ensureConfigFetched(); + } + + /* PlatformUtilsService methods */ + getDevice() { + return this.platformUtilsService.getDevice(); + } + + getDeviceString() { + return this.platformUtilsService.getDeviceString(); + } + + getClientType() { + return this.platformUtilsService.getClientType(); + } + + isFirefox() { + return this.platformUtilsService.isFirefox(); + } + + isChrome() { + return this.platformUtilsService.isChrome(); + } + + isEdge() { + return this.platformUtilsService.isEdge(); + } + + isOpera() { + return this.platformUtilsService.isOpera(); + } + + isVivaldi() { + return this.platformUtilsService.isVivaldi(); + } + + isSafari() { + return this.platformUtilsService.isSafari(); + } + + isChromium() { + return this.platformUtilsService.isChromium(); + } + + isMacAppStore() { + return this.platformUtilsService.isMacAppStore(); + } + + isPopupOpen() { + return this.platformUtilsService.isPopupOpen(); + } + + launchUri(uri: string, options?: any) { + return this.platformUtilsService.launchUri(uri, options); + } + + getApplicationVersion() { + return this.platformUtilsService.getApplicationVersion(); + } + + getApplicationVersionNumber() { + return this.platformUtilsService.getApplicationVersionNumber(); + } + + supportsWebAuthn(win: Window) { + return this.platformUtilsService.supportsWebAuthn(win); + } + + supportsDuo() { + return this.platformUtilsService.supportsDuo(); + } + + supportsAutofill() { + return this.platformUtilsService.supportsAutofill(); + } + + supportsFileDownloads() { + return this.platformUtilsService.supportsFileDownloads(); + } + + isDev() { + return this.platformUtilsService.isDev(); + } + + isSelfHost() { + return this.platformUtilsService.isSelfHost(); + } + + supportsSecureStorage() { + return this.platformUtilsService.supportsSecureStorage(); + } + + getAutofillKeyboardShortcut() { + return this.platformUtilsService.getAutofillKeyboardShortcut(); + } +}