mirror of
https://github.com/bitwarden/browser
synced 2026-02-12 14:34:02 +00:00
Expose userEnvironment$ Method
This commit is contained in:
@@ -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<Environment>;
|
||||
|
||||
/**
|
||||
* 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<string>;
|
||||
|
||||
/**
|
||||
* 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<Environment>;
|
||||
/**
|
||||
* 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<Environment | undefined>;
|
||||
}
|
||||
|
||||
@@ -181,6 +181,14 @@ export class DefaultEnvironmentService implements EnvironmentService {
|
||||
return PRODUCTION_REGIONS.concat(additionalRegions);
|
||||
}
|
||||
|
||||
userEnvironment$(userId: UserId): Observable<Environment> {
|
||||
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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user