diff --git a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts index 934c35f806..c992ecd78c 100644 --- a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts +++ b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts @@ -42,7 +42,6 @@ import { EventType } from "@bitwarden/common/enums"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { AsyncActionsModule, @@ -56,7 +55,8 @@ import { SelectModule, ToastService, } from "@bitwarden/components"; -import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { GeneratorServicesModule } from "@bitwarden/generator-components"; +import { CredentialGeneratorService, GenerateRequest, Generators } from "@bitwarden/generator-core"; import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core"; import { EncryptedExportType } from "../enums/encrypted-export-type.enum"; @@ -81,6 +81,7 @@ import { ExportScopeCalloutComponent } from "./export-scope-callout.component"; ExportScopeCalloutComponent, UserVerificationDialogComponent, PasswordStrengthV2Component, + GeneratorServicesModule, ], }) export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { @@ -175,14 +176,14 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { private destroy$ = new Subject(); private onlyManagedCollections = true; + private onGenerate$ = new Subject(); constructor( protected i18nService: I18nService, protected toastService: ToastService, protected exportService: VaultExportServiceAbstraction, protected eventCollectionService: EventCollectionService, - protected passwordGenerationService: PasswordGenerationServiceAbstraction, - private platformUtilsService: PlatformUtilsService, + protected generatorService: CredentialGeneratorService, private policyService: PolicyService, private logService: LogService, private formBuilder: UntypedFormBuilder, @@ -218,6 +219,17 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + // Wire up the password generation for the password-protected export + this.generatorService + .generate$(Generators.password, { on$: this.onGenerate$ }) + .pipe(takeUntil(this.destroy$)) + .subscribe((generated) => { + this.exportForm.patchValue({ + filePassword: generated.credential, + confirmFilePassword: generated.credential, + }); + }); + if (this.organizationId) { this.organizations$ = this.organizationService .memberOrganizations$(userId) @@ -302,10 +314,7 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { } generatePassword = async () => { - const [options] = await this.passwordGenerationService.getOptions(); - const generatedPassword = await this.passwordGenerationService.generatePassword(options); - this.exportForm.get("filePassword").setValue(generatedPassword); - this.exportForm.get("confirmFilePassword").setValue(generatedPassword); + this.onGenerate$.next({ source: "export" }); }; submit = async () => { diff --git a/libs/tools/export/vault-export/vault-export-ui/tsconfig.json b/libs/tools/export/vault-export/vault-export-ui/tsconfig.json index 1732817986..6f2a0242da 100644 --- a/libs/tools/export/vault-export/vault-export-ui/tsconfig.json +++ b/libs/tools/export/vault-export/vault-export-ui/tsconfig.json @@ -9,6 +9,7 @@ "@bitwarden/common/*": ["../../../../common/src/*"], "@bitwarden/components": ["../../../../components/src"], "@bitwarden/generator-core": ["../../../../tools/generator/core/src"], + "@bitwarden/generator-components": ["../../../../tools/generator/components/src"], "@bitwarden/generator-history": ["../../../../tools/generator/extensions/history/src"], "@bitwarden/generator-legacy": ["../../../../tools/generator/extensions/legacy/src"], "@bitwarden/generator-navigation": ["../../../../tools/generator/extensions/navigation/src"],