diff --git a/libs/common/src/platform/abstractions/environment.service.ts b/libs/common/src/platform/abstractions/environment.service.ts index 0293d68903c..c1a2b072534 100644 --- a/libs/common/src/platform/abstractions/environment.service.ts +++ b/libs/common/src/platform/abstractions/environment.service.ts @@ -92,9 +92,23 @@ export interface Environment { * The environment service. Provides access to set the current environment urls and region. */ export abstract class EnvironmentService { + /** + * An observable that follows the environment of the active user if there is one or falls + * back to the environment saved in global state. + */ abstract environment$: Observable; + + /** + * An observable that follows the cloud web vault url for the active user if there is one + * or falls back to the cloud web vault url saved in global state. + */ abstract cloudWebVaultUrl$: Observable; + /** + * Gets an observable stream of the configured Environment for a given user. + * @param userId The id of the user to get the environment for. + */ + abstract userEnvironment$(userId: UserId): Observable; /** * Retrieve all the available regions for environment selectors. * @@ -127,6 +141,8 @@ export abstract class EnvironmentService { /** * Get the environment from state. Useful if you need to get the environment for another user. + * + * @deprecated Use {@link userEnvironment$} with a {@link UserId} to get the environment for a given user. */ abstract getEnvironment(userId?: string): Promise; } diff --git a/libs/common/src/platform/services/default-environment.service.ts b/libs/common/src/platform/services/default-environment.service.ts index 59956ede7ae..0b0f16e2480 100644 --- a/libs/common/src/platform/services/default-environment.service.ts +++ b/libs/common/src/platform/services/default-environment.service.ts @@ -181,6 +181,14 @@ export class DefaultEnvironmentService implements EnvironmentService { return PRODUCTION_REGIONS.concat(additionalRegions); } + userEnvironment$(userId: UserId): Observable { + return this.stateProvider + .getUser(userId, USER_ENVIRONMENT_KEY) + .state$.pipe( + map((environment) => this.buildEnvironment(environment?.region, environment?.urls)), + ); + } + /** * Get the region configuration for the given region. */