From f6b49b0404989449ad808b2aea58beedf68bbba8 Mon Sep 17 00:00:00 2001 From: Miles Blackwood Date: Thu, 12 Jun 2025 13:41:07 -0400 Subject: [PATCH] Remove Injectable decorator from class, use safeProvider. --- .../background/notification.background.ts | 8 ++--- .../browser/src/background/main.background.ts | 9 ++++++ .../src/services/jslib-services.module.ts | 16 ++++++++-- .../default-change-login-password.service.ts | 30 ++++--------------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/apps/browser/src/autofill/background/notification.background.ts b/apps/browser/src/autofill/background/notification.background.ts index ab570dc5361..09b875b3eef 100644 --- a/apps/browser/src/autofill/background/notification.background.ts +++ b/apps/browser/src/autofill/background/notification.background.ts @@ -43,7 +43,7 @@ import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; import { TaskService } from "@bitwarden/common/vault/tasks"; import { SecurityTaskType } from "@bitwarden/common/vault/tasks/enums"; import { SecurityTask } from "@bitwarden/common/vault/tasks/models/security-task"; -import { DefaultChangeLoginPasswordService } from "@bitwarden/vault"; +import { ChangeLoginPasswordService } from "@bitwarden/vault"; import { openUnlockPopout } from "../../auth/popup/utils/auth-popout-window"; import { BrowserApi } from "../../platform/browser/browser-api"; @@ -140,6 +140,7 @@ export default class NotificationBackground { private themeStateService: ThemeStateService, private userNotificationSettingsService: UserNotificationSettingsServiceAbstraction, private taskService: TaskService, + private changeLoginPasswordService: ChangeLoginPasswordService, protected messagingService: MessagingService, ) {} @@ -401,10 +402,7 @@ export default class NotificationBackground { ): Promise { const { activeUserId, securityTask, cipher } = message.data; const domain = Utils.getDomain(sender.tab.url); - const passwordChangeUri = await DefaultChangeLoginPasswordService.create( - { nativeFetch: fetch }, - { getClientType: () => "browser" }, - ).getChangePasswordUrl(cipher); + const passwordChangeUri = await this.changeLoginPasswordService.getChangePasswordUrl(cipher); const authStatus = await this.getAuthStatus(); diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index c353cdb4f93..d6c6993f868 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -229,6 +229,7 @@ import { KeyService as KeyServiceAbstraction, } from "@bitwarden/key-management"; import { BackgroundSyncService } from "@bitwarden/platform/background-sync"; +import { ChangeLoginPasswordService, DefaultChangeLoginPasswordService } from "@bitwarden/vault"; import { IndividualVaultExportService, IndividualVaultExportServiceAbstraction, @@ -415,6 +416,8 @@ export default class MainBackground { ipcContentScriptManagerService: IpcContentScriptManagerService; ipcService: IpcService; + changeLoginPasswordService: ChangeLoginPasswordService; + onUpdatedRan: boolean; onReplacedRan: boolean; loginToAutoFill: CipherView = null; @@ -1208,6 +1211,11 @@ export default class MainBackground { messageListener, ); + this.changeLoginPasswordService = new DefaultChangeLoginPasswordService( + this.apiService, + this.platformUtilsService, + ); + this.notificationBackground = new NotificationBackground( this.accountService, this.authService, @@ -1224,6 +1232,7 @@ export default class MainBackground { this.themeStateService, this.userNotificationSettingsService, this.taskService, + this.changeLoginPasswordService, this.messagingService, ); diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 15fd6b0fbaf..e413a333fa7 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -187,7 +187,10 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/platform/abstractions/messaging.service"; -import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { + PlatformUtilsService, + PlatformUtilsService as PlatformUtilsServiceAbstraction, +} from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory"; import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; @@ -324,7 +327,11 @@ import { import { SafeInjectionToken } from "@bitwarden/ui-common"; // This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop. // eslint-disable-next-line no-restricted-imports -import { PasswordRepromptService } from "@bitwarden/vault"; +import { + ChangeLoginPasswordService, + DefaultChangeLoginPasswordService, + PasswordRepromptService, +} from "@bitwarden/vault"; import { IndividualVaultExportService, IndividualVaultExportServiceAbstraction, @@ -1559,6 +1566,11 @@ const safeProviders: SafeProvider[] = [ InternalMasterPasswordServiceAbstraction, ], }), + safeProvider({ + provide: ChangeLoginPasswordService, + useClass: DefaultChangeLoginPasswordService, + deps: [ApiService, PlatformUtilsService], + }), ]; @NgModule({ diff --git a/libs/vault/src/services/default-change-login-password.service.ts b/libs/vault/src/services/default-change-login-password.service.ts index 459bd34121d..b1838ddbb6b 100644 --- a/libs/vault/src/services/default-change-login-password.service.ts +++ b/libs/vault/src/services/default-change-login-password.service.ts @@ -1,36 +1,16 @@ -import { Inject, Injectable } from "@angular/core"; - +import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { ChangeLoginPasswordService } from "../abstractions/change-login-password.service"; -interface PartialApiService { - nativeFetch(request: Request): Promise; -} -interface PartialPlatformUtilsService { - getClientType(): string; -} -@Injectable() export class DefaultChangeLoginPasswordService implements ChangeLoginPasswordService { - private apiService: PartialApiService; - private platformUtilsService: PartialPlatformUtilsService; - constructor( - @Inject("ApiService") apiService: PartialApiService, - @Inject("PlatformUtilsService") platformUtilsService: PartialPlatformUtilsService, - ) { - this.apiService = apiService; - this.platformUtilsService = platformUtilsService; - } - - static create(apiService: PartialApiService, platformUtilsService: PartialPlatformUtilsService) { - const instance = new DefaultChangeLoginPasswordService(null!, null!); - instance.apiService = apiService; - instance.platformUtilsService = platformUtilsService; - return instance; - } + private apiService: ApiService, + private platformUtilsService: PlatformUtilsService, + ) {} /** * @inheritDoc