mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 21:50:15 +00:00
Implement observable return with concatMap.
This commit is contained in:
@@ -48,6 +48,8 @@ import { Fido2CredentialView } from "@bitwarden/common/vault/models/view/fido2-c
|
||||
import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view";
|
||||
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
|
||||
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
|
||||
import { GenerateRequest } from "@bitwarden/generator-core";
|
||||
import { GeneratedCredential } from "@bitwarden/generator-history";
|
||||
|
||||
// FIXME (PM-22628): Popup imports are forbidden in background
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
@@ -234,7 +236,9 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
||||
private themeStateService: ThemeStateService,
|
||||
private totpService: TotpService,
|
||||
private accountService: AccountService,
|
||||
private generatePasswordCallback: () => Promise<string>,
|
||||
private generatePasswordCallback: (
|
||||
$on: Observable<GenerateRequest>,
|
||||
) => Observable<GeneratedCredential>,
|
||||
private addPasswordCallback: (password: string) => Promise<void>,
|
||||
) {
|
||||
this.initOverlayEventObservables();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import "core-js/proposals/explicit-resource-management";
|
||||
|
||||
import {
|
||||
concatMap,
|
||||
filter,
|
||||
firstValueFrom,
|
||||
from,
|
||||
@@ -227,6 +228,8 @@ import {
|
||||
PasswordGenerationServiceAbstraction,
|
||||
UsernameGenerationServiceAbstraction,
|
||||
} from "@bitwarden/generator-legacy";
|
||||
import { GenerateRequest } from "@bitwarden/generator-core";
|
||||
import { GeneratedCredential } from "@bitwarden/generator-history";
|
||||
import {
|
||||
DefaultImportMetadataService,
|
||||
ImportApiService,
|
||||
@@ -2044,6 +2047,18 @@ export default class MainBackground {
|
||||
await this.atRiskCipherUpdaterService.init();
|
||||
}
|
||||
|
||||
yieldGeneratedPassword = ($on: Observable<GenerateRequest>): Observable<GeneratedCredential> => {
|
||||
return $on.pipe(
|
||||
concatMap(async () => {
|
||||
const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {};
|
||||
const password = await this.passwordGenerationService.generatePassword(options);
|
||||
const credential = new GeneratedCredential(password, "password", new Date());
|
||||
|
||||
return credential;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
generatePassword = async (): Promise<string> => {
|
||||
const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {};
|
||||
return await this.passwordGenerationService.generatePassword(options);
|
||||
|
||||
Reference in New Issue
Block a user