From 59a483696bceb86a719ed907ee652f525375a28c Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Tue, 25 Mar 2025 12:49:28 -0500 Subject: [PATCH] update getManagedEnvironment so it can be used in all clients --- .../platform/services/browser-environment.service.ts | 10 +++++----- apps/web/src/app/platform/web-environment.service.ts | 7 +++++++ .../src/platform/abstractions/environment.service.ts | 7 +++++++ .../platform/services/default-environment.service.ts | 7 +++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/browser/src/platform/services/browser-environment.service.ts b/apps/browser/src/platform/services/browser-environment.service.ts index 278ec6f5cff..cd5e7d4cbf6 100644 --- a/apps/browser/src/platform/services/browser-environment.service.ts +++ b/apps/browser/src/platform/services/browser-environment.service.ts @@ -35,7 +35,7 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService { return false; } - const managedEnv = await this.getManagedEnvironment(); + const managedEnv = await this.getManagedEnvironment(); const env = await firstValueFrom(this.environment$); const urls = env.getUrls(); @@ -50,9 +50,9 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService { ); } - getManagedEnvironment(): Promise { + getManagedEnvironment(): Promise { return devFlagEnabled("managedEnvironment") - ? new Promise((resolve) => resolve(devFlagValue("managedEnvironment"))) + ? new Promise((resolve) => resolve(devFlagValue("managedEnvironment") as T)) : new Promise((resolve, reject) => { if (chrome.storage.managed == null) { return resolve(null); @@ -63,13 +63,13 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService { return reject(chrome.runtime.lastError); } - resolve(result.environment); + resolve(result.environment as T); }); }); } async setUrlsToManagedEnvironment() { - const env = await this.getManagedEnvironment(); + const env = await this.getManagedEnvironment(); await this.setEnvironment(Region.SelfHosted, { base: env.base, webVault: env.webVault, diff --git a/apps/web/src/app/platform/web-environment.service.ts b/apps/web/src/app/platform/web-environment.service.ts index 1df842d6b31..e4cc6c723cb 100644 --- a/apps/web/src/app/platform/web-environment.service.ts +++ b/apps/web/src/app/platform/web-environment.service.ts @@ -100,6 +100,13 @@ export class WebEnvironmentService extends DefaultEnvironmentService { // This return shouldn't matter as we are about to leave the current window return chosenRegionConfig.urls; } + + /** + * No-op for web environment service. + */ + async getManagedEnvironment(): Promise { + return null; + } } export class WebCloudEnvironment extends CloudEnvironment { diff --git a/libs/common/src/platform/abstractions/environment.service.ts b/libs/common/src/platform/abstractions/environment.service.ts index 4a10f856893..582e4f91377 100644 --- a/libs/common/src/platform/abstractions/environment.service.ts +++ b/libs/common/src/platform/abstractions/environment.service.ts @@ -134,4 +134,11 @@ export abstract class EnvironmentService { * @deprecated Use {@link getEnvironment$} instead. */ abstract getEnvironment(userId?: string): Promise; + + /** + * Get the managed environment configuration if one exists. + * @typeParam T - The type of the managed environment configuration. + * @returns A promise that resolves to the managed environment configuration or null if it doesn't exist. + */ + abstract getManagedEnvironment(): Promise; } diff --git a/libs/common/src/platform/services/default-environment.service.ts b/libs/common/src/platform/services/default-environment.service.ts index df55693ba0b..e01c828aeaf 100644 --- a/libs/common/src/platform/services/default-environment.service.ts +++ b/libs/common/src/platform/services/default-environment.service.ts @@ -293,6 +293,13 @@ export class DefaultEnvironmentService implements EnvironmentService { const global = await firstValueFrom(this.globalState.state$); await this.stateProvider.getUser(userId, USER_ENVIRONMENT_KEY).update(() => global); } + + /** + * No-op for default environment service. + */ + async getManagedEnvironment(): Promise { + return null; + } } function formatUrl(url: string): string {