From 92797c99c7bfe423197ac1d76aeedd1396130cf2 Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Thu, 10 Apr 2025 15:35:19 -0500 Subject: [PATCH] Rename to remove "view" and "default" --- .../two-factor-auth.component.spec.ts | 12 ++++---- .../two-factor-auth.component.ts | 28 +++++++++---------- ...ce.ts => two-factor-auth-cache.service.ts} | 26 ++++++++--------- 3 files changed, 33 insertions(+), 33 deletions(-) rename libs/auth/src/common/services/auth-request/{default-two-factor-form-cache.service.ts => two-factor-auth-cache.service.ts} (78%) diff --git a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts index 7b85ede78d5..beae2478fd5 100644 --- a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts +++ b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.spec.ts @@ -34,7 +34,7 @@ import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/sp import { UserId } from "@bitwarden/common/types/guid"; import { DialogService, ToastService } from "@bitwarden/components"; -import { DefaultTwoFactorFormCacheService } from "../../common/services/auth-request/default-two-factor-form-cache.service"; +import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service"; import { TwoFactorAuthComponentService } from "./two-factor-auth-component.service"; @@ -71,7 +71,7 @@ describe("TwoFactorAuthComponent", () => { let anonLayoutWrapperDataService: MockProxy; let mockEnvService: MockProxy; let mockLoginSuccessHandlerService: MockProxy; - let mockTwoFactorFormCacheService: MockProxy; + let mockTwoFactorAuthCacheService: MockProxy; let mockUserDecryptionOpts: { noMasterPassword: UserDecryptionOptions; @@ -112,9 +112,9 @@ describe("TwoFactorAuthComponent", () => { anonLayoutWrapperDataService = mock(); - mockTwoFactorFormCacheService = mock(); - mockTwoFactorFormCacheService.getCachedTwoFactorFormData.mockReturnValue(null); - mockTwoFactorFormCacheService.init.mockResolvedValue(); + mockTwoFactorAuthCacheService = mock(); + mockTwoFactorAuthCacheService.getCachedTwoFactorAuth.mockReturnValue(null); + mockTwoFactorAuthCacheService.init.mockResolvedValue(); mockUserDecryptionOpts = { noMasterPassword: new UserDecryptionOptions({ @@ -200,7 +200,7 @@ describe("TwoFactorAuthComponent", () => { { provide: EnvironmentService, useValue: mockEnvService }, { provide: AnonLayoutWrapperDataService, useValue: anonLayoutWrapperDataService }, { provide: LoginSuccessHandlerService, useValue: mockLoginSuccessHandlerService }, - { provide: DefaultTwoFactorFormCacheService, useValue: mockTwoFactorFormCacheService }, + { provide: TwoFactorAuthCacheService, useValue: mockTwoFactorAuthCacheService }, ], }); diff --git a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts index 035584e8ed5..5af56654dbd 100644 --- a/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts +++ b/libs/auth/src/angular/two-factor-auth/two-factor-auth.component.ts @@ -46,7 +46,7 @@ import { ToastService, } from "@bitwarden/components"; -import { DefaultTwoFactorFormCacheService } from "../../common/services/auth-request/default-two-factor-form-cache.service"; +import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service"; import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service"; import { TwoFactorAuthAuthenticatorIcon, @@ -74,7 +74,7 @@ import { /** * Interface for the cache data structure */ -interface TwoFactorFormCacheData { +interface TwoFactorCacheData { token?: string; remember?: boolean; selectedProviderType?: TwoFactorProviderType; @@ -103,7 +103,7 @@ interface TwoFactorFormCacheData { ], providers: [ { - provide: DefaultTwoFactorFormCacheService, + provide: TwoFactorAuthCacheService, }, ], }) @@ -180,7 +180,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { private anonLayoutWrapperDataService: AnonLayoutWrapperDataService, private environmentService: EnvironmentService, private loginSuccessHandlerService: LoginSuccessHandlerService, - private twoFactorFormCacheService: DefaultTwoFactorFormCacheService, + private twoFactorCacheService: TwoFactorAuthCacheService, ) {} async ngOnInit() { @@ -190,11 +190,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { this.listenForAuthnSessionTimeout(); // Initialize the cache - await this.twoFactorFormCacheService.init(); + await this.twoFactorCacheService.init(); // Load persisted form data if available let loadedCachedProviderType = false; - const persistedData = this.twoFactorFormCacheService.getCachedTwoFactorFormData(); + const persistedData = this.twoFactorCacheService.getCachedTwoFactorAuth(); if (persistedData) { if (persistedData.token) { this.form.patchValue({ token: persistedData.token }); @@ -231,11 +231,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { /** * Save specific form data fields to the cache */ - async saveFormDataWithPartialData(data: Partial) { + async saveFormDataWithPartialData(data: Partial) { // Get current cached data - const currentData = this.twoFactorFormCacheService.getCachedTwoFactorFormData(); + const currentData = this.twoFactorCacheService.getCachedTwoFactorAuth(); - this.twoFactorFormCacheService.cacheTwoFactorFormData({ + this.twoFactorCacheService.cacheTwoFactorAuth({ token: data?.token ?? currentData?.token ?? "", remember: data?.remember ?? currentData?.remember ?? false, selectedProviderType: @@ -250,7 +250,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { * Save all current form data to the cache */ async saveFormData() { - const formData: TwoFactorFormCacheData = { + const formData: TwoFactorCacheData = { token: this.tokenFormControl.value || undefined, remember: this.rememberFormControl.value ?? undefined, selectedProviderType: this.selectedProviderType, @@ -347,7 +347,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { const rememberValue = remember ?? this.rememberFormControl.value ?? false; // Persist form data before submitting - this.twoFactorFormCacheService.cacheTwoFactorFormData({ + this.twoFactorCacheService.cacheTwoFactorAuth({ token: tokenValue, remember: rememberValue, selectedProviderType: this.selectedProviderType, @@ -375,7 +375,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { async selectOtherTwoFactorMethod() { // Persist current form data before navigating to another method - this.twoFactorFormCacheService.cacheTwoFactorFormData({ + this.twoFactorCacheService.cacheTwoFactorAuth({ token: "", remember: false, selectedProviderType: this.selectedProviderType, @@ -396,7 +396,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { await this.setAnonLayoutDataByTwoFactorProviderType(); // Update the persisted provider type when a new one is chosen - this.twoFactorFormCacheService.cacheTwoFactorFormData({ + this.twoFactorCacheService.cacheTwoFactorAuth({ token: "", remember: false, selectedProviderType: response.type, @@ -481,7 +481,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy { private async handleAuthResult(authResult: AuthResult) { // Clear form cache - this.twoFactorFormCacheService.clearCachedTwoFactorFormData(); + this.twoFactorCacheService.clearCachedTwoFactorAuth(); if (await this.handleMigrateEncryptionKey(authResult)) { return; // stop login process diff --git a/libs/auth/src/common/services/auth-request/default-two-factor-form-cache.service.ts b/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts similarity index 78% rename from libs/auth/src/common/services/auth-request/default-two-factor-form-cache.service.ts rename to libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts index bc70f8fbfdb..70a03787874 100644 --- a/libs/auth/src/common/services/auth-request/default-two-factor-form-cache.service.ts +++ b/libs/auth/src/common/services/auth-request/two-factor-auth-cache.service.ts @@ -22,7 +22,7 @@ export class TwoFactorAuthCache { } } -export interface TwoFactorFormData { +export interface TwoFactorAuthData { token?: string; remember?: boolean; selectedProviderType?: TwoFactorProviderType; @@ -36,7 +36,7 @@ export interface TwoFactorFormData { * after 2 minutes. */ @Injectable() -export class DefaultTwoFactorFormCacheService { +export class TwoFactorAuthCacheService { private viewCacheService: ViewCacheService = inject(ViewCacheService); private configService: ConfigService = inject(ConfigService); @@ -44,9 +44,9 @@ export class DefaultTwoFactorFormCacheService { private featureEnabled: boolean = false; /** - * Signal for the cached TwoFactorFormData. + * Signal for the cached TwoFactorAuthData. */ - private defaultTwoFactorAuthCache: WritableSignal = + private twoFactorAuthCache: WritableSignal = this.viewCacheService.signal({ key: TWO_FACTOR_AUTH_CACHE_KEY, initialValue: null, @@ -65,14 +65,14 @@ export class DefaultTwoFactorFormCacheService { } /** - * Update the cache with the new TwoFactorFormData. + * Update the cache with the new TwoFactorAuthData. */ - cacheTwoFactorFormData(data: TwoFactorFormData): void { + cacheTwoFactorAuth(data: TwoFactorAuthData): void { if (!this.featureEnabled) { return; } - this.defaultTwoFactorAuthCache.set({ + this.twoFactorAuthCache.set({ token: data.token, remember: data.remember, selectedProviderType: data.selectedProviderType, @@ -81,24 +81,24 @@ export class DefaultTwoFactorFormCacheService { } /** - * Clears the cached TwoFactorFormData. + * Clears the cached TwoFactorAuthData. */ - clearCachedTwoFactorFormData(): void { + clearCachedTwoFactorAuth(): void { if (!this.featureEnabled) { return; } - this.defaultTwoFactorAuthCache.set(null); + this.twoFactorAuthCache.set(null); } /** - * Returns the cached TwoFactorFormData when available. + * Returns the cached TwoFactorAuthData when available. */ - getCachedTwoFactorFormData(): TwoFactorAuthCache | null { + getCachedTwoFactorAuth(): TwoFactorAuthCache | null { if (!this.featureEnabled) { return null; } - return this.defaultTwoFactorAuthCache(); + return this.twoFactorAuthCache(); } }