Commit Graph

84 Commits

Author SHA1 Message Date
Matt Gibson 62ad39e697
Ps/pm 5965/better config polling (#8325)
* Create tracker that can await until expected observables are received.

* Test dates are almost equal

* Remove unused class method

* Allow for updating active account in accout service fake

* Correct observable tracker behavior

Clarify documentation

* Transition config service to state provider

Updates the config fetching behavior to be lazy and ensure that any emitted value has been updated if older than a configurable value (statically compiled).

If desired, config fetching can be ensured fresh through an async.

* Update calls to config service in DI and bootstrapping

* Migrate account server configs

* Fix global config fetching

* Test migration rollback

* Adhere to implementation naming convention

* Adhere to abstract class naming convention

* Complete config abstraction rename

* Remove unnecessary cli config service

* Fix builds

* Validate observable does not complete

* Use token service to determine authed or unauthed config pull

* Remove superfluous factory config

* Name describe blocks after the thing they test

* Remove implementation documentation

Unfortunately the experience when linking to external documentation is quite poor. Instead of following the link and retrieving docs, you get a link that can be clicked to take you out of context to the docs. No link _does_ retrieve docs, but lacks indication in the implementation that documentation exists at all.

On the balance, removing the link is the better experience.

* Fix storybook
2024-03-27 10:03:09 -07:00
Justin Baur f7014a973c
[PM-7071] Fallback to Emitting `null` When No Active User (#8486)
* Fallback to Emitting `null` When No Active User

* Fix Tests

* Update Test Names to Follow Convention

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>

* Fix CLI Build

---------

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
2024-03-26 12:06:33 -04:00
Daniel James Smith eea4d5407d
Add the missing languages to the translation.service (#8459)
This enables it being shown as anm option with the language selector on the individual clients

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
2024-03-25 11:12:32 +01:00
Oscar Hinton e767295c86
[PM-5979] Refactor EnvironmentService (#8040)
Refactor environment service to emit a single observable. This required significant changes to how the environment service behaves and tackles much of the tech debt planned for it.
2024-03-21 09:09:44 -07:00
Daniel James Smith 123bee868c
Update locales used on browser, desktop and web (#8371)
Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
2024-03-18 12:14:10 -04:00
Conner Turnbull b99153a016
[AC-2156] Billing State Provider Migration (#8133)
* Added billing account profile state service

* Update usages after removing state service functions

* Added migrator

* Updated bw.ts and main.background.ts

* Removed comment

* Updated state service dependencies to include billing service

* Added missing mv3 factory and updated MainContextMenuHandler

* updated autofill service and tests

* Updated the remaining extensions usages

* Updated desktop

* Removed subjects where they weren't needed

* Refactored billing service to have a single setter to avoid unecessary emissions

* Refactored has premium guard to return an observable

* Renamed services to match ADR

f633f2cdd8/docs/architecture/clients/presentation/angular.md (abstract--default-implementations)

* Updated property names to be a smidgen more descriptive and added jsdocs

* Updated setting of canAccessPremium to automatically update when the underlying observable emits

* Fixed build error after merge conflicts

* Another build error from conflict

* Removed autofill unit test changes from conflict

* Updated login strategy to not set premium field using state service

* Updated CLI to use billing state provider

* Shortened names a bit

* Fixed build
2024-03-15 14:53:05 -05:00
Jared Snider 161fb1da5d
Auth/PM-5263 - TokenService State Provider Migration (#7975)
* PM-5263 - Token Service state migration - (1) Got key and state definitions setup (2) Ported over core state service getTimeoutBasedStorageOptions method logic into local determineStorageLocation method (3) Updated majority of methods to use state provider state

* PM-5263 - StateSvc - add TODO to remove timeoutBasedStorageOptions + other state methods after migration code complete.

* PM-5263 - TokenSvc - ClearToken method - (1) Update signature to remove user id as it wasn't used and it simplifies the new state provider implementation (2) Convert away from state svc to state provider state.

* PM-5263 - TokenService - update deps - WIP on circular dep issues.

* PM-5263 -  To resolve circular dep issues between VaultTimeoutSettingsSvc and TokenService: (1) For writes, require callers to pass in vault timeout data (2) For reads, we can just check both locations. This approach has 1 less state call than the previous implementation and is safe as long as the clear logic properly works and is executed anytime a user changes their vault timeout action (lock or log out) & vault timeout (numeric value)

* PM-5263 - VaultTimeoutSettingsSvc - Set token calls now updated to include vault timeout info.

* PM-5263 - Update API Service - add state service and look up vault timeout details and pass to token service when setting token info.

* PM-5263 - TokenService - update service dependencies.

* PM-5263 - TokenService - Add new getAccessTokenByUserId method for state service use case.

* PM-5263 - StateSvc - remove migrated methods and try to replace all usages of getAccessToken. WIP

* PM-5263 - TokenSvc Migration - start on migrator

* PM-5263 - (1) TokenSvc - Build new clearAccessTokenByUserId which is required by state service (2) TokenSvc - Update getToken to take an optional userId to handle another state service case (3) Add some documentation to TokenSvc abstraction.

* PM-5263 - StateService - finish updating all calls within the state service which accessed token service state directly with calls to the new token service methods instead.

* PM-5263 - TokenSvc Abstraction - Add more docs

* PM-5263 - TokenSvc abstraction - more doc tweaks

* PM-5263 - Web state service - add new token service dependency.

* PM-5263  - User API Key Login Strategy - Update to pull vault timeout action and vault timeout from state service in order to pass to new token service endpoints for setting API key client id and secret.

* PM-5263  - (1) Remove TokenSvc owned state from account (2) StateSvc - remove account scaffold logic for clearing removed account data. The same functionality will exist in the state provider framework via lifecycle hooks cleaning up this data and users getting initialized with null data by default.

* PM-5263 - Add token service dependency to state service (WIP - desktop deps not working)

* PM-5263 - Update services module on desktop and browser to add token svc dependency

* PM-5263 - API service factory - add state service factory dependency that I missed initially to get browser building.

* PM-5263 - TokenSvc - getToken/setToken/decodeToken --> getAccessToken/setAccessToken/decodeAccessToken

* PM-5263 - TokenSvc State Provider Migrator - WIP - update expected acct type to match actual account

* PM-5263 - TokenService - clearToken renamed to clearTokens

* PM-5263 - CLI - NodeApiService - add state service dep to get CLI building.

* PM-5263 - StateDefinitions - use unique state definition names

* PM-5263 - StateSvc - remove getTimeoutBasedStorageOptions as no longer used.

* PM-5263 - TokenSvc - Add TODO for figuring out how to store tokens in secure storage.

* PM-5263 - StateSvc - remove get/set 2FA token - references migrated later.

* PM-5263 - TODO: figure out if using same key definition names is an issue

* PM-5263 - TokenServiceStateProviderMigrator written

* PM-5263 - TokenServiceStateProviderMigrator - (1) Don't update legacy account if we only added a new state in state provider for 2FA token (2) Use for loop for easier debugging

* PM-5263 - TokenServiceStateProviderMigrator test - WIP - migration testing mostly complete and passing. Rollback logic TODO.

* PM-5263 - TokenServiceStateProviderMigrator - Add rollback logic to restore 2FA token from users to global.

* PM-5263 - TokenServiceStateProviderMigrator - Refactor rollback to only set account once as not necessary to set it every time.

* PM-5263 - TokenServiceStateProviderMigrator tests - test all rollback scenarios

* PM-5263 - Remove TODO as don't need unique key def names as long as state def keys are unique.

* PM-5263 - TokenSvc - update clearAccessTokenByUserId to use proper state provider helper method to set state.

* PM-5263 - Revert accidentally committing settings.json changes.

* PM-5263 - TokenSvc - update all 2FA token methods to require email so we can user specifically scope 2FA tokens while still storing them in global storage.

* PM-5263 - Update all token service 2FA set / get / clear methods to pass in email.

* PM-5263  - JslibServices module - add missed login service to login strategy svc deps.

* PM-5263 - VaultTimeoutSettingsService - setVaultTimeoutOptions - rename token to accesToken for clarity.

* PM-5263 - (1) TokenSvc - remove getAccessTokenByUserId and force consumers to use getAccessToken w/ optional user id to keep interface small (2) TokenSvc - attempt to implement secure storage on platforms that support it for access & refresh token storage (3) StateSvc - replace usage of getAccessTokenByUserId with getAccessToken

* PM-5263 - TokenSvc - add platform utils and secure storage svc deps

* PM-5263 - TODO: figure out what to do with broken migration

* PM-5263 - TODO: update tests in light of latest 2FA token changes.

* PM-5263 - TokenSvc - clean up TODO

* PM-5263 - We should have tests for the token service.

* PM-5263 - TokenSvc - setAccessToken - If platform supports secure storage and we are saving an access token, remove the access token from memory and disk to fully migrate to secure storage.

* PM-5263 - TokenSvc - getAccessToken - Update logic to look at memory and disk first always and secure storage last to support the secure storage migration

* PM-5263 - TokenSvc - setAccesToken - if user id null on a secure storage supporting platform, throw error.

* PM-5263 - TokenService - (1) Refresh token now stored in secure storage (2) Refresh token set now private as we require a user id to store it in secure storage and we can use the setTokens method to enforce always setting the access token and refresh token together in order to extract a user id from the refresh token. (3) setTokens clientIdClientSecret param now optional

* PM-5263 - TokenServiceStateProviderMigrator - update migration to take global but user scoped 2FA token storage changes into account.

* PM-5263 - Remove old migration as it references state we are removing. Bump min version.

Co-authored-by: Matt Gibson <git@mgibson.dev>

* PM-5263 - TokenService - 2FA token methods now backed by global state record which maps email to individual tokens.

* PM-5263 - WIP on Token Svc migrator and test updates based on new 2FA token storage changes.

* PM-5263 - TokenSvc - (1) Add jira tickets to clean up state migration (2) Add state to track secure storage migration to improve # of reads to get data

* PM-5263 - StateDef - consolidate name of token domain state defs per feedback from Justin + update migration tests

* PM-5263 - TokenSvc - fix error message and add TODO

* PM-5263 - Update token service migration + tests to pass after all 2FA token changes.

* PM-5263 - Fix all login strategy tests which were failing due to token state provider changes + the addition of the loginService as a dependency in the base login strategy.

* PM-5263 - Register TokenService state provider migration with migrator

* PM-5263 - TokenSvc state migration - set tokens after initializing account

* PM-5263 - TokenService changes - WIP - convert from ActiveUserStateProvider to just SingleUserStateProvider to avoid future circ dependency issues.

Co-authored-by: Jake Fink <jlf0dev@users.noreply.github.com>

* PM-5263 - TokenSvc - create getSecureStorageOptions for centralizing all logic for getting data out of SecureStorage.

* PM-5263 - TokenSvc - (1) Refactor determineStorageLocation to also determine secure storage - created a TokenStorageLocation string enum to remove magic strings (2) Refactor setAccessToken to use switch (3) Refactor clearAccessTokenByUserId to clear all locations and not early return on secure storage b/c we only use secure storage if disk is the location but I don't want to require vault timeout data for this method.

* PM-5263 - TokenSvc - getDataFromSecureStorage - Refactor to be more generic for easier re-use

* PM-5263 - TokenSvc - Convert refresh token methods to use single user state and require user ids

* PM-5263 - VaultTimeoutSettingsSvc - get user id and pass to access and refresh token methods.

* PM-5263 - TokenSvc - refactor save secure storage logic into private helper.

* PM-5263 - Base Login Strategy - per discussion with Justin, move save of tokens to before account initialization as we can always derive the user id from the access token. This will ensure that the account is initialized with the proper authN status.

* PM-5263 - TokenSvc - latest refactor - update all methods to accept optional userId now as we can read active user id from global state provider without using activeUserStateProvider (thus, avoiding a circular dep and having to have every method accept in a mandatory user id).

* PM-5263 - VaultTimeoutSettingsService - remove user id from token calls

* PM-5263 - TokenSvc - update all places we instantiate token service to properly pass in new deps.

* PM-5263 - TokenSvc migration is now 27th instead of 23rd.

* PM-5263  - Browser - MainContextMenuHandler - Update service options to include PlatformUtilsServiceInitOptions as the TokenService requires that and the TokenService is now injected on the StateService

* PM-5263 - TokenSvc migration test - update rollback tests to start with correct current version

* PM-5263 - Create token service test file - WIP

* PM-5263 - TokenSvc - tests WIP - instantiates working.

* PM-5263 - TokenSvc - set2FAToken - use null coalesce to ensure record is instantiated for new users before setting data on it.

* PM-5263 - TokenService tests - WIP - 2FA token tests.

* PM-5263 - Worked with Justin to resolve desktop circular dependency issue by adding SUPPORTS_SECURE_STORAGE injection token instead of injecting PlatformUtilsService directly into TokenService.

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* PM-5263 - TokenSvc tests - WIP - (1) Update TokenSvc instantiation to use new supportsSecureStorage (2) Test TwoFactorToken methods

* PM-5263 - Fix SUPPORTS_SECURE_STORAGE injection token to properly call supportsSecureStorage message

* PM-5263 - Token state testing

* PM-5263 - TokenState fix name of describe

* PM-5263 - TokenService - export TokenStorageLocation for use in tests.

* PM-5263 - TokenSvc Tests WIP

* PM-5263 - TokenSvc tests - access token logic mostly completed.

* PM-5263 - TokenSvc Tests - more WIP - finish testing access token methods.

* PM-5263 - TokenSvc WIP - another clear access token test.

* PM-5263 - TokenSvc tests - WIP - SetTokens tested.

* PM-5263 - Tweak test name

* PM-5263 - TokenSvc tests - remove unnecessary describe around 2FA token methods.

* PM-5263 - TokenSvc.clearAccessTokenByUserId renamed to just clearAccessToken

* PM-5263 - TokenSvc - refactor clearTokens logic and implement individual clear logic which doesn't require vault timeout setting information.

* PM-5263 - TokenSvc - Replace all places we have vaultTimeout: number with vaultTimeout: number | null to be accurate.

* PM-5263 - TokenSvc.clearTokens - add check for user id; throw if not found

* PM-5263 - TokenService - test clearTokens

* PM-5263 - TokenSvc Tests - setRefreshToken tested

* PM-5263 - TokenSvc tests - getRefreshToken tested + added a new getAccessToken test

* PM-5263 - TokenSvc - ClearRefreshToken scenarios tested.

* PM-5263 - TokenSvc.clearRefreshToken tests - fix copy pasta

* PM-5263 - TokenSvc tests - (1) Fix mistakes in refresh token testing (2) Test setClientId for all scenarios

* PM-5263 - TokenSvc tests - (1) Add some getClientId tests (2) clarify lack of awaits

* PM-5263 - TokenSvc Tests - WIP - getClientId && clearClientId

* PM-5263 - TokenService - getClientSecret - fix error message

* PM-5263 - TokenService tests - test all client secret methods

* PM-5263 - Update TokenSvc migration to 30th migration

* PM-5263 - TokenService - update all tests to initialize data to undefined now that fake state provider supports faking data based on specific key definitions.

* PM-5263 - (1) TokenSvc.decodeAccessToken - update static method's error handling (2) TokenSvc tests - test all decodeAccessToken scenarios

* PM-5263 - TokenSvc - (1) Add DecodedAccessToken type (2) Refactor getTokenExpirationDate logic to use new type and make proper type checks for numbers for exp claim values.

* PM-5263 - TokenSvc tests - test getTokenExpirationDate method.

* PM-5263 - TokenSvc - (1) Update DecodedAccessToken docs (2) Tweak naming in tokenSecondsRemaining

* PM-5263 - TokenSvc abstraction - add jsdoc for tokenSecondsRemaining

* PM-5263 - TokenSvc tests - test tokenSecondsRemaining

* PM-5263 - TokenSvc - DecodedAccessToken type - update sstamp info

* PM-5263 - TokenService - fix flaky tokenSecondsRemaining tests by locking time

* PM-5263 - TokenSvc Tests - Test tokenNeedsRefresh

* PM-5263 - (1) TokenSvc - Refactor getUserId to add extra safety (2) TokenSvc tests - test getUserId

* PM-5263  - (1) TokenSvc - refactor getUserIdFromAccessToken to handle decoding errors (2) TokenSvc tests - test getUserIdFromAccessToken

* PM-5263 - (1) TokenSvc - Refactor getEmail to handle decoding errors + check for specific, expected type (2) TokenSvc tests - test getEmail

* PM-5263 - TokenSvc tests - clean up comment

* PM-5263 - (1) TokenSvc - getEmailVerified - refactor (2) TokenSvc tests - add getEmailVerified tests

* PM-5263  - (1) TokenSvc - refactor getName (2) TokenSvc tests - test getName

* PM-5263 - (1) TokenSvc - refactor getIssuer (2) TokenSvc tests - test getIssuer

* PM-5263 - TokenSvc - remove unnecessary "as type" statements now that we have a decoded access token type

* PM-5263  - (1) TokenSvc - refactor getIsExternal (2) TokenSvc Tests - test getIsExternal

* PM-5263  - TokenSvc abstraction - tune up rest of docs.

* PM-5263 - TokenSvc - clean up promise<any> and replace with promise<void>

* PM-5263 - TokenSvc abstraction - more docs.

* PM-5263  - Clean up TODO as I've tested every method in token svc.

* PM-5263 - (1) Extract JWT decode logic into auth owned utility function out of the token service (2) Update TokenService decode logic to use new utility function (3) Update LastPassDirectImportService + vault.ts to use new utility function and remove token service dependency.  (4) Update tests + migrate tests to new utility test file.

* PM-5263 - Rename decodeJwtTokenToJson to decode-jwt-token-to-json to meet lint rules excluding capitals

* PM-5263 - TokenSvc + tests - fix all get methods to return undefined like they did before instead of throwing an error if a user id isn't provided.

* PM-5263 - Services.module - add missing token service dep

* PM-5263 - Update token svc migrations to be 32nd migration

* PM-5263 - Popup - Services.module - Remove token service as it no longer requires a background service due to the migration to state provider. The service definition in jslib-services module is enough.

* PM-5263 - BaseLoginStrategy - Extract email out of getTwoFactorToken method call for easier debugging.

* PM-5263 - Login Comp - Set email into memory on login service so that base login strategy can access user email for looking up 2FA token stored in global state.

* PM-5263 - (1) LoginComp - remove loginSvc.setEmail call as no longer necessary + introduced issues w/ popup and background in browser extension (2) AuthReq & Password login strategies now just pass in email to buildTwoFactor method.

* PM-5263 - SsoLoginSvc + abstraction - Add key definition and get/set methods for saving user email in session storage so it persists across the SSO redirect.

* PM-5263 - Base Login Strategy - BuildTwoFactor - only try to get 2FA token if we have an email to look up their token

* PM-5263 - Remove LoginService dependency from LoginStrategyService

* PM-5263 - (1) Save off user email when they click enterprise SSO on all clients in login comp (2) Retrieve it and pass it into login strategy in SSO comp

* PM-5263 - (1) TokenSvc - update 2FA token methods to be more safe in case user removes record from local storage (2) Add test cases + missing clearTwoFactorToken tests

* PM-5263 - Browser SSO login - save user email for browser SSO process

* PM-5263 - Finish removing login service from login strategy tests.

* PM-5263 - More removals of the login service from the login strategy tests.

* PM-5263 - Main.ts - platformUtilsSvc no longer used in TokenSvc so remove it from desktop main.ts

* PM-5263 - Fix failing login strategy service tests

* PM-5263 - Bump token svc migration values to migration 35 after merging in main

* PM-5263 - Bump token svc migration version

* PM-5263 - TokenService.clearTwoFactorToken - use delete instead of setting values to null per discussion with Justin

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* PM-5263 - TokenSvc + decode JWT token tests - anonymize my information

Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>

* PM-5263 - TokenSvc tests - update clear token tests based on actual deletion

* PM-5263 - Add docs per PR feedback

* PM-5263 - (1) Move ownership of clearing two factor token on rejection from server to base login strategy (2) Each login strategy that supports remember 2FA logic now persists user entered email in its data (3) Base login strategy processTwoFactorResponse now clears 2FA token (4) Updated base login strategy tests to affirm the clearing of the 2FA token

* Update libs/auth/src/common/login-strategies/login.strategy.ts

Co-authored-by: Jake Fink <jfink@bitwarden.com>

* Update libs/auth/src/common/login-strategies/password-login.strategy.ts

Co-authored-by: Jake Fink <jfink@bitwarden.com>

* PM-5263 - Login Strategy - per PR feedback, add jsdoc comments to each method I've touched for this PR.

* PM-5263 - (1) TokenSvc - adjust setTokens, setAccessToken, setRefreshToken, and clearRefreshToken based on PR feedback to remove optional user ids where possible and improve public interface (2) TokenSvc Abstraction - update docs and abstractions based on removed user ids and changed logic (3) TokenSvc tests - update tests to add new test cases, remove no longer relevant ones, and update test names.

* PM-5263 - Bump migrations again

---------

Co-authored-by: Matt Gibson <git@mgibson.dev>
Co-authored-by: Jake Fink <jlf0dev@users.noreply.github.com>
Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
Co-authored-by: Jake Fink <jfink@bitwarden.com>
2024-03-15 11:50:04 -04:00
Justin Baur 1d76e80afb
Refactor State Providers (#8273)
* Delete A Lot Of Code

* Fix Tests

* Create SingleUserState Provider Once

* Update Manual Instantiations

* Fix Service Factory

* Delete More

* Delete Unused `updatePromise`

* `postStorageSave` -> `doStorageSave`

* Update Comment

* Fix jslib-services
2024-03-14 16:38:22 -05:00
Matt Gibson ddac10136f
Fix missed service dependency changes (#8305) 2024-03-12 17:12:12 +01:00
Matt Gibson 1f41d7871c
Ps/pm-6636/angular-specific-browser-platform-utils (#8211)
* Remove Unused services

* Split platform utils between foreground and background

* Respond to clipboard clearing and biometric unlock

* Use new browser platform utils

* Fix folder name

* Fix imports

* biometrics is supported only on windows and mac

* Reject native messaging with errors

We're now going through the runtime background, which expects error objects in message failures
2024-03-12 11:25:03 -04:00
Matt Gibson f4150ffda6
[PM-6511] New i18n for angular (#8122)
* Use state provider to store preferred language

* migrate preferred language

* Use new i18n provider to get LOCAL_ID

* Fix preloaded english i18n

This is a mock service that forces english translations, it doesn't need the i18n interface that allows changing of locales.

* PR improvements

* Fixup merge
2024-03-11 13:59:19 -04:00
Cesar Gonzalez 51f482dde9
[PM-5880] Refactor browser platform utils service to remove `window` references (#7885)
* [PM-5880] Refactor Browser Platform Utils Service to Remove Window Service

* [PM-5880] Implementing BrowserClipboardService to handle clipboard logic between the BrowserPlatformUtils and offscreen document

* [PM-5880] Adjusting how readText is handled within BrowserClipboardService

* [PM-5880] Adjusting how readText is handled within BrowserClipboardService

* [PM-5880] Working through implementation of chrome offscreen API usage

* [PM-5880] Implementing jest tests for the methods added to the BrowserApi class

* [PM-5880] Implementing jest tests for the OffscreenDocument class

* [PM-5880] Working through jest tests for BrowserClipboardService

* [PM-5880] Adding typing information to the clipboard methods present within the BrowserPlatformUtilsService

* [PM-5880] Working on adding ServiceWorkerGlobalScope typing information

* [PM-5880] Updating window references when calling BrowserPlatformUtils methods

* [PM-5880] Finishing out jest tests for the BrowserClipboardService

* [PM-5880] Finishing out jest tests for the BrowserClipboardService

* [PM-5880] Implementing jest tests to validate the changes within BrowserApi

* [PM-5880] Implementing jest tests to ensure coverage within OffscreenDocument

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Removing unused catch statements

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Fixing broken tests
2024-03-06 16:33:38 +00:00
Cesar Gonzalez 16c5fe65ca
[PM-5876] Adjust the `LpFilelessImporter.supressDownload` method to inject through the `executeScript` API instead within manifest v3 (#7787)
* [PM-5876] Adjust LP Fileless Importer to Suppress Download with DOM Append in Manifest v3

* [PM-5876] Incorporating jest tests for affected logic

* [PM-5876] Fixing jest test that leverages rxjs

* [PM-5876] Updating documentation within BrowserApi.executeScriptInTab

* [PM-5876] Implementing jest tests for the new LP suppress download content scripts

* [PM-5876] Adding a change to webpack to ensure we do not package the mv2 side script for `lp-suppress-import-download.mv2.ts` if building the extension for mv3

* [PM-5876] Implementing changes based on feedback during code review

* [PM-5876] Implementing changes based on feedback during code review

* [PM-5876] Implementing changes based on feedback during code review

* [PM-5876] Implementing changes based on feedback during code review

* [PM-5876] Implementing a configuration to feed the script injection of the Fileless Importer CSV download supression script
2024-03-05 19:39:58 +00:00
Justin Baur c3eba7f2c8
[PM-6404] Fully Integrate `clearOn` Events (#8134)
* Add New KeyDefinitionOption

* Add New Services

* Add WebStorageServiceProvider Tests

* Update Error Message

* Add `UserKeyDefinition`

* Fix Deserialization Helpers

* Fix KeyDefinition

* Add `UserKeyDefinition`

* Fix Deserialization Helpers

* Fix KeyDefinition

* Move `ClearEvent`

* Cleanup

* Fix Imports

* Integrate onClear Events

* Remove Accidental Addition

* Fix Test

* Add VaultTimeoutService Tests

* Only Register When Current State is Null

* Address Feedback
2024-03-04 20:33:25 +00:00
Matt Gibson 5677d6265e
Ps/pm 5537/move biometric unlock to state providers (#8099)
* Establish biometric unlock enabled in state providers

* Use biometric state service for biometric state values

* Migrate biometricUnlock

* Fixup Dependencies

* linter and import fixes

* Fix injection

* Fix merge

* Use boolean constructor as mapper

* Conform to documented test naming conventions

* Commit documentation suggestion

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>

* Fix merge commit

* Fix test names

---------

Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
2024-03-01 10:17:06 -05:00
Cesar Gonzalez d176a678e0
[PM-5882] Adjust usage of `chrome.extension.getBackgroundPage` to ensure no conflicts exist due to the service worker (#8054) 2024-02-27 22:01:00 +00:00
Justin Baur 87c75e5ac8
[PM-6404] Initial Clear Events Code (#8029)
* Add New KeyDefinitionOption

* Add New Services

* Add WebStorageServiceProvider Tests

* Update Error Message

* Add `UserKeyDefinition`

* Fix Deserialization Helpers

* Fix KeyDefinition

* Add `UserKeyDefinition`

* Fix Deserialization Helpers

* Fix KeyDefinition

* Move `ClearEvent`

* Cleanup

* Fix Imports

* Remove `updateMock`

* Call Super in Web Implementation

* Use Better Type to Avoid Casting

* Better Error Docs

* Move StorageKey Creation to Function

* Throw Aggregated Error for Failures
2024-02-27 21:58:31 +00:00
Jonathan Prusik 929b5ebec3
[PM-5568] Implement Badge Settings state provider (#8112)
* create badge settings state provider

* replace state service get/set disableBadgeCounter with badge settings service equivalent

* migrate disableBadgeCounter account setting to badge settings state provider

* cleanup and address PR suggestions
2024-02-27 21:03:12 +00:00
Cesar Gonzalez 968355d820
[PM-5881] Adjust usage of the `chrome.extension.getViews` API to ensure expected behavior in mv3 is not modified (#7842)
* [PM-5742] Rework Usage of Extension APIs that Cannot be Called with the Background Service Worker

* [PM-5742] Implementing jest tests for the updated BrowserApi methods

* [PM-5742] Implementing jest tests to validate logic within added API calls

* [PM-5742] Implementing jest tests to validate logic within added API calls

* [PM-5742] Fixing broken Jest tests

* [PM-5742] Fixing linter error

* [PM-5881] Adjust usage of the `chrome.extension.getViews` API to ensure expected behavior in manifest v3

* [PM-5881] Reworking how we handle early returns from `reloadOpenWindows`

* [PM-5881] Implementing jest test to validate changes within BrowserApi.reloadOpenWindows
2024-02-23 19:01:45 +00:00
Jonathan Prusik 34a8d9af86
[PM-6383] Migrate clearClipboard account setting to autofill settings service (#8022)
* migrate clearClipboard account setting to autofill settings state provider

* replace state service get/set clearClipboard with autofill settings service equivalents

* PR suggestions cleanup
2024-02-23 13:52:13 -05:00
Jake Fink 19a373d87e
[PM-6211] Create key generation service (#7939)
* create key generation service

* replace old key generation service and add references

* use key generation service in key connector service

* use key generation service in send service

* user key generation service in access service

* use key generation service in device trust service

* fix tests

* fix browser

* add createKeyFromMaterial and tests

* create ephemeral key

* fix tests

* rename method and add returns docs

* ignore material in destructure

* modify test

* specify material as key material

* pull out magic strings to properties

* make salt optional and generate if not provided

* fix test

* fix parameters

* update docs to include link to HKDF rfc
2024-02-23 08:48:15 -05:00
Cesar Gonzalez 57ac4e141b
[PM-5741] Reworking usage of `window` object in BrowserApi.reloadExtension method (#8021)
* [PM-5741] Reworking usage of `window` object in BrowserApi.reloadExtension method

* [PM-5741] Reworking usage of `window` object in BrowserApi.reloadExtension method
2024-02-22 22:21:24 +00:00
Matt Gibson 220268b25d
Fix #7970 browser builds (#8055)
This PR removed the setting of a session-synced subject but failed to remove session sync from the browser instance of state service.
2024-02-22 22:00:42 +00:00
Matt Gibson 56bffb04bb
Ps/pm 5533/migrate decrypted user key (#7970)
* Move user key memory state to state providers

Note: state service observable change is because these updates are no longer internal to the class, but reporter directly to account service through crypto service on update of a user key

* remove decrypted user key state

Note, we're going to move the encrypted cryptoSymmetric key (and associated master key encrypted user keys)  as part of the master key service creation. Crypto service will no longer be responsible for the encrypted forms of user key.

* Deprecate notices belong on abstraction

* Allow for single-direction status updates

This is necessary since we don't want to have to guarantee that the update to logged out occurs after the update to locked.

* Remove deprecated subject

It turns out the set for cryptoMasterKey was also unused 🎉
2024-02-22 15:07:26 -05:00
Robyn MacCallum c037b1dbbe
Rename jest directory to spec (#7935) 2024-02-21 09:38:27 -05:00
Justin Baur 1ff7bdd014
[PM-6172] Run `localStorage` migrations for web (#7900)
* Create MigrationRunner

- Create MigrationRunner Service for running migrations in StateService
- Create web override so that migrations also run against `localStorage`

* Fix Web StateService

* Fix WebMigrationRunner

* Fix CLI

* Fix ElectronStateService

* Update Comment

* More Common Scenarios
2024-02-14 08:52:13 -05:00
Matt Gibson b0edcb81af
Ps/run-foreground-derived-state-in-zone (#7861)
* Sync derived state through memory storage

* Run foreground derived state in NgZone

* fix tests
2024-02-08 14:04:38 -05:00
Cesar Gonzalez a1745b2dae
[PM-5742] Rework Usage of Extension APIs that Cannot be Called with the Background Service Worker (#7667)
* [PM-5742] Rework Usage of Extension APIs that Cannot be Called with the Background Service Worker

* [PM-5742] Implementing jest tests for the updated BrowserApi methods

* [PM-5742] Implementing jest tests to validate logic within added API calls

* [PM-5742] Implementing jest tests to validate logic within added API calls

* [PM-5742] Fixing broken Jest tests

* [PM-5742] Fixing linter error
2024-02-07 21:20:53 +00:00
Cesar Gonzalez fb17cb7b99
[PM-5739] Remove Usage of Angular within Background Script (#7659) 2024-02-06 22:24:14 +00:00
Will Martin cb8849c355
Add eslint rule no-floating-promises (#7789)
* add eslint rule no-floating-promises

* add eslint-disable comment to offending lines
2024-02-02 15:13:37 -05:00
Matt Gibson 1da6733e71
JSON stringify memory items (#7731)
* JSON stringify memory items

stringification is required so they can be reliably sent through messaging

* Simplify null handling
2024-01-29 19:42:58 +00:00
Jared Snider 2c1d215b71
Auth/PM-5242 - Create new User Verification dialog and form input components which support PIN and biometrics verification (#7536)
* PM-5242 - First working draft of copying out web CL implementation of user verification form and dialog components into standalone libs/auth components which could be used in any client.

* PM-5242 - Rename UserVerificationFormComponent to UserVerificationFormInputComponent b/c it doesn't actually have a form and is meant to slot into a form as an input.

* PM-5242 - Update libs/auth angular index to take renamed component into account

* PM-5242 - Clean up UserVerificationDialogComponent as have much cleaner design approach now (maintain existing func while simply adding new requirements for client side validation for passkeys)

* PM-5242 - UserVerificationFormInput component - WIP draft of new client and server split of user verification logic

* PM-5242 - UserVerificationFormInput - WIP - Lots of progress on client side verification layout - more to do

* PM-5242 - UserVerificationFormInputComponent - Add hasMultipleVerificationMethods property so we can only show alternate methods if user has them.

* PM-5242 - UserVerificationFormInputComponent - rename hasMultipleVerificationMethods to hasMultipleClientVerificationOptions

* PM-5242 - Add new user verification biometrics fingerprint icon with proper secondary fill so it displays properly on all themes.

* PM-5242 - Create enum for tracking client user verification states

* PM-5242 - UserVerificationFormInputComponent - WIP - (1) Got biometrics layout working except for error state (2) Emitting active client verification option and biometrics result to dialog (3) Properly identifying if biometrics is enabled in a platform agnostic way (4) Translations TODO

* PM-5242 - UserVerificationDialogComponent - (1) Wire up new inputs and outputs for UserVerificationFormInput (2) Don't show submit button when clientside biometrics verification active

* PM-5242 - UserVerificationFormInputComponent - wired up biometrics failure and retry handling + re-arranged comp properties to put inputs & outputs at the top

* PM-5242 - UserVerificationFormInput component - Add logic to prevent currently active client verification method from being shown an option

* PM-5242 - UserVerificationFormInput - adjust margins

* PM-5242 - User verification dialog and form input comps - replace Verification with VerificationWithSecret type where applicable

* PM-5242 - UserVerificationFormComp - Default to server for backwards compatibility and to avoid requiring the input at all

* PM-5242 - UserVerificationFormInputComp - (1) Rename processChanges to processSecretChanges (2) Short circuit processSecretChanges when biometrics is active (3) Add new function for determining type of verification that has a secret.

* PM-5242 - UserVerificationDialog - Support custom, optional callout in dialog body.

* PM-5242 - UserVerificationDialogComp - support custom confirm button text and type.

* PM-5242 - UserVerificationDialog - Add user verification dialog result type to allow for handling all possible verification scenarios

* PM-5242 - UserVerificationFormInputComp - tweak comment

* PM-5242 - UserVerificationFormInput comp html - add placeholder text for no client verifications found scenario

* PM-5242 - UserVerificationDialogComponent - (1) Add confirm & cancel to dialog result (2) Add cancel method vs using bitDialogClose for specificity (3) Adjust naming of output property to properly specify that it is scoped to client verification (4) Adjust layout of dialog html to handle when no client side verification methods are found.

* PM-5242 - UserVerificationFormInput - Clean up test code

* PM-5242 - UserVerificationFormInput - For server verification, we don't need to check if the user has a local master key hash as we will generate a hash to send to the server for comparison.

* PM-5242 - UserVerificationFormInput html - Remove now unnecessary dev warning as I've provided a default

* PM-5242 - UserVerification Dialog & Form Input - add translations on all clients for all visible text.

* PM-5242 - UserVerificationFormInput html - remove no active client verification handling from form input comp as it is instead emitted upwards to parent dialog component to be handled there.

* PM-5242 - UserVerificationDialogComp - (1) Make UserVerificationDialogResult.noAvailableClientVerificationMethods optional because it isn't needed in cancel flows (thanks Will) (2) Modify static open to intercept closed observable event in order to always return a UserVerificationDialogResult as BitDialog returns empty string when the user clicks the x

* PM-5242 - UserVerificationDialogComp - Simplify dialog param names to remove redundant dialog

* PM-5242 - UserVerificationDialogParams - update comments to match new names

* PM-5242 - UserVerificationDialog Storybook - WIP first draft

* PM-5242 - UserVerificationDialogStoryComponent - WIP - try out having imports the same as the standalone component

* PM-5242 - UserVerificationDialogStoryComponent - more WIP - building now - some stuff displaying

* PM-5242 - UserVerificationDialogStoryComponent - some progress on providers setup

* PM-5242 - Not going to use storybook for user verification dialog

* PM-5242 - UserVerificationDialogComp - move types into own file + add docs

* PM-5242 - Update auth index to export user-verification-dialog.types

* PM-5242 - UserVerificationFormInput & UserVerificationService - Extract out getAvailableVerificationOptions logic into service

* PM-5242 -UserVerificationDialogComponent - Update close logic to handle escape key undefined scenario

* PM-5242 - UserVerificationFormInput - add getInvalidSecretErrorMessage for properly determining invalid secret translation

* PM-5242 - UserVerificationDialogComp - Refactor submit logic to handle different return methodologies in existing MP and OTP user verification service code vs new PIN flow (e.g., throwing an error instead of returning false)

* PM-5242 - PinCryptoService - change error logs to warnings per discussion with Justin

* PM-5242 - UserVerificationFormInput - Biometrics flow on desktop - remove accidentally added period in couldNotCompleteBiometrics translation key.

* PM-5242 - UserVerificationFormInput HTML - Re-arrange order of other client verification options to match design

* PM-5242 - UserVerificationFormInputComponent - Reset inputs as untouched on change of client verification method.

* PM-5242 - UserVerificationDialogComponent - Remove TODO as existing secret change logic turns invalidSecret false when biometrics is swapped to.

* PM-5242 - UserVerificationFormInputComponent - getInvalidSecretErrorMessage - fix PIN error message not being returned.

* PM-5242 - UserVerificationDialogComponent - Add documentation and examples to open method.

* PM-5242 - UserVerificationDialogComponent - tweak open docs

* PM-5242 - Remove accidental period from translation keys on browser & web

* PM-5242 - UserVerificationFormInputComponent - OTP flow needed button module to work

* PM-5242 - UserVerificationDialogParams - Add docs explaining that noAvailableClientVerificationMethods is only for desktop & browser.

* PM-5242 - User-verification-form-input - Adjust layout to meet new design requirements - (1) On load, send OTP without user clicking a button (2) Allow resending of the codes (3) show a code sent message for 3 seconds

* PM-5242 - Browser User Verification - Instantiate PinCryptoService and UserVerification service AFTER instantiating vaultTimeoutSettingsService so that it isn't undefined at run time.

* PM-5242 - JslibServices Module - UserVerificationService - add missing PlatformUtilsServiceAbstraction dependency.

* PM-5242 - Desktop Native Messaging Service - Wrap biometric getUserKeyFromStorage call in try catch because it throws an error if the user cancels the biometrics prompt and doesn't send a response to the browser extension when using the biometrics unlock bridge to the desktop app and OS.

* PM-5242 - Browser Extension - NativeMessagingBackground - if the desktop biometricUnlock command is executed with a canceled (not adjusting misspelling to keep side effects at a min) response, don't bother continuing.

* PM-5242 - BrowserCryptoService - When retrieving the user key via desktop biometrics, return null for user key if the user fails or cancels the biometrics prompt. Otherwise, if there is a user key in memory after unlock, biometrics user verification will always just return the user key from state regardless of if the user has successfully passed the biometrics prompt or not.

* PM-5242 - BrowserCryptoService - extra comments

* PM-5242 - Clean up translations - (1) Remove unused defaultUserVerificationDialogConfirmBtnText (2) Refactor name of defaultUserVerificationDialogTitle to just be verificationRequired which matches existing naming conventions.

* PM-5242 - CLI - fix order of service instantiations to ensure that vaultTimeoutSettingsService isn't undefined for PinCryptoService and UserVerificationService

* PM-5242 - Rename UserVerificationDialogParams to UserVerificationDialogOptions to match existing naming conventions of other CL comps.

* PM-5242 - UserVerificationDialogComponent - dialogParams renamed to dialogOptions

* PM-5242 - UserVerificationService Abstraction - Per PR feedback, use keyof for verificationType

* PM-5242 - UserVerificationBiometricsIcon - Per PR feedback, use https://jakearchibald.github.io/svgomg/ to optimize SVG by 50%.

* PM-5242 - Per PR feedback, clarify UserVerificationDialogOptions.clientSideOnlyVerification comment.

* PM-5242 - UserVerificationTypes - Add comments clarifying all text passed to the UserVerificationDialog are translation keys

* PM-5242 - UserVerificationDialogComp - fix extra new line per PR feedback

* PM-5242 - UserVerificationDialogTypes - per PR feedback and discussion with Will M., export ButtonType from CL so we (and consumers of the dialog) can properly import it via standard CL import.

* PM-5242 - BrowserCryptoService - Adjust comments per PR feedback.

* PM-5242 - UserVerificationDialogComponent - make ActiveClientVerificationOption readonly as it only for component html

* PM-5242 - UserVerificationDialogComp html - finish comment

* PM-5242 - BrowserCryptoService - add returns js doc per PR feedback.

* PM-5242 - UserVerificationDialogComponent - per PR feedback, add unexpected error toast.

* PM-5242  - UserVerificationService - getAvailableVerificationOptions - update params to use keyof like abstraction

* PM-5242 - Mark all existing client specific implemetations of user verification as deprecated.
2024-01-25 14:03:27 -05:00
Justin Baur c1d5351075
[PM-5535] Migrate Environment Service to StateProvider (#7621)
* Migrate EnvironmentService

* Move Migration Test Helper

* Claim StateDefinition

* Add State Migration

* Update StateServices

* Update EnvironmentService Abstraction

* Update DI

* Update Browser Instantiation

* Fix BrowserEnvironmentService

* Update Desktop & CLI Instantiation

* Update Usage

* Create isStringRecord helper

* Fix Old Tests

* Use Existing AccountService

* Don't Rely on Parameter Mutation

* Fix Conflicts
2024-01-24 14:21:50 -05:00
Cesar Gonzalez 609296ad2b
[PM-5617] Re-add setting to turn off browser autofill (#7592)
* [PM-5617] Re-Add Setting to Turn Off Default Browser Autofill

* [PM-5617] Re-Add Setting to Turn Off Default Browser Autofill

* [PM-5617] Removing the privacy optional permission from Firefox

* [PM-5617] Adding jest tests to validate the behavior within BrowserApi

* [PM-5617] Adjusting messaging based on feedback from design

* [PM-5617] Adjusting messaging based on feedback from design

* [PM-5617] Adjusting messaging based on feedback from design

* [PM-5617] Removing unnecessary configService dependency
2024-01-23 19:23:08 +00:00
Matt Gibson a102f8d90a
Hard code account switching off on Safari (#7510)
The better place for this is arguably in environment configurations, but I don't want to expand that functionality more than it has to in hopes that this is a rare/one-off occurrence.
2024-01-17 15:01:24 -05:00
Matt Gibson 160a636fa0
Move key types to central location (#7531) 2024-01-17 07:27:44 -05:00
Matt Gibson 46a3834f46
Add state for everHadUserKey (#7208)
* Migrate ever had user key

* Add DI for state providers

* Add state for everHadUserKey

* Use ever had user key migrator

Co-authored-by: SmithThe4th <gsmithwalter@gmail.com>
Co-authored-by: Carlos Gonçalves <LRNcardozoWDF@users.noreply.github.com>
Co-authored-by: Jason Ng <Jcory.ng@gmail.com>

* Fix test from merge

* Prefer stored observables to getters

getters create a new observable every time they're called, whereas one set in the constructor is created only once.

* Fix another merge issue

* Fix cli background build

---------

Co-authored-by: SmithThe4th <gsmithwalter@gmail.com>
Co-authored-by: Carlos Gonçalves <LRNcardozoWDF@users.noreply.github.com>
Co-authored-by: Jason Ng <Jcory.ng@gmail.com>
2024-01-10 11:51:45 -05:00
Matt Gibson 92f593df08
Remove unnecessary complex types (#7451)
#7290 introduced these types, but during development we switched over to specifying dependencies in type parameters instead of an object. This change meant we no longer needed these `Type` or `ShapeToInstance` types, greatly simplifying the types related to derived state.
2024-01-04 16:50:55 -05:00
Justin Baur 5e11cb212d
Combined State (#7383)
* Introduce Combined State

* Cleanup Test

* Update Fakes

* Address PR Feedback

* Update libs/common/src/platform/state/implementations/default-active-user-state.ts

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>

* Prettier

* Get rid of ReplaySubject reference

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
2024-01-04 16:30:20 -05:00
Matt Gibson 06affa9654
Rework derived state (#7290)
* Remove derived state from state classes

* Create provider for derived state

Derived state is automatically stored to memory storage, but can be derived from any observable.

* Fixup state provider method definitions

* Test `DefaultDerivedState`

* remove implementation notes

* Write docs for derived state

* fixup derived state provider types

* Implement buffered delayUntil operator

* Move state types to a common module

* Move mock ports to centra location

* Alias DerivedStateDependency type

* Add dependencies to browser

* Prefer internal rxjs operators for ref counting

* WIP

* Ensure complete on subjects

* Foreground/background messaging for browser

Defers work for browser to the background

* Test foreground port behaviors

* Inject foreground and background derived state services

* remove unnecessary class field

* Adhere to required options

* Add dderived state to CLI

* Prefer type definition in type parameters to options

* Prefer instance method

* Implements factory methods for common uses

* Remove nothing test

* Remove share subject reference

Share manages connector subjects internally and will reuse them until
refcount is 0 and the cleanup time has passed. Saving our own reference
just risks memory leaks without real testability benefits.

* Fix interaction state
2024-01-04 14:47:49 -05:00
Bernd Schoolmann 1b4717a78f
[PM-3343] Capture TOTP QR codes from websites in the browser extension (#5985)
* Implement totp capture for browser extensions
2024-01-03 13:20:17 -05:00
Matt Gibson a682f2a0ef
[PM-5468] Ensure prototypes available on memory stored objects (#7399)
* Hide account switcher in addEdit generator

* Handle AddEditCipher deserialization

* Opaque types are not serializable

* Better handle jsonification of login uris

* Ensure we don't overwrite original with clone

* Ensure cipherView prototype is always restored if it exists
2024-01-02 10:46:45 -05:00
Matt Gibson bbdf704763
Target messages to only the interested ports (#7301) 2023-12-21 14:01:48 -05:00
Matt Gibson bc1f93d098
Add missing state provider factories (#7262) 2023-12-18 12:39:05 +00:00
Matt Gibson b4dbace7a6
Do not drop optional parameters in overrides (#7176) 2023-12-11 13:44:23 -05:00
Cesar Gonzalez 7db844baf2
[PM-5048] Query params are not persisting in extension popout window (#7019)
* [PM-5048] Query params are not persisting in extension popout window

* [PM-5048] Reverting how we identify whether the user is popping out the current tab;

* [PM-5048] Adding jest test to validate skipping parsing of the extension path

* [PM-5048] Adding jest test to validate skipping parsing of the extension path

* [PM-5048] Reworking implementation to ensure that popout window query params remain persistent

* [PM-5048] Reworking implementation to ensure that appended query params do not remain persistent, but popout window query params do remain persistent. Fixing issues within vault item popouts and adding jest tests to verify those fixes

* [PM-5048] Modifying how query params are set within vault popout windows

* [PM-5048] Running prettier
2023-12-08 22:26:29 +00:00
Cesar Gonzalez e5b8fd4388
[PM-5148] Removing Browser Autofill Override Setting and Add Message (#7110)
* [PM-5148] Removing Browser Autofill Override Setting and Add Message

* [PM-5148] Removing translation keys

* [PM-5148] Removing translation keys

* [PM-5148] Modifying how we present the link to users to ensure translations can be more effective
2023-12-07 20:39:28 +00:00
rr-bw ac899bebeb
[PM-194] Browser Account Switcher UI (#6772)
* Handle switch messaging

TODO: handle loading state for account switcher

* Async updates required for state

* Fallback to email for current account avatar

* Await un-awaited promises

* Remove unnecessary Prune

Prune was getting confused in browser and deleting memory in browser on
account switch. This method isn't needed since logout already removes
memory data, which is the condition for pruning

* Fix temp password in browser

* Use direct memory access until data is serializable

Safari uses a different message object extraction than firefox/chrome
and is removing `UInt8Array`s. Until all data passed into StorageService
is guaranteed serializable, we need to use direct access in state
service

* Reload badge and context menu on switch

* Gracefully switch account as they log out.

* Maintain location on account switch

* Remove unused state definitions

* Prefer null for state

undefined can be misinterpreted to indicate a value has not been set.

* Hack: structured clone in memory storage

We are currently getting dead objects on account switch due to updating
the object in the foreground state service. However, the storage service
is owned by the background. This structured clone hack ensures that all
objects stored in memory are owned by the appropriate context

* Null check nullable values

active account can be null, so we should include null safety in the
equality

* Correct background->foreground switch command

* Already providing background memory storage

* Handle connection and clipboard on switch account

* Prefer strict equal

* Ensure structuredClone is available to jsdom

This is a deficiency in jsdom --
https://github.com/jsdom/jsdom/issues/3363 -- structured clone is well
supported.

* Fixup types in faker class

* add avatar and simple navigation to header

* add options buttons

* add app-header to necessary pages

* add back button and adjust avatar sizes

* add helper text when account limit reached

* convert magic number to constant

* add clarifying comment

* adjust homepage header styles

* navigate to previousp page upon avatar click when already on '/account-switcher'

* move account UI to own component

* add i18n

* show correct auth status

* add aria-hidden to icons

* use listbox role

* add screen reader accessibility to account component

* more SR a11y updates to account component

* add hover and focus states to avatar

* refactor hover and focus states for avatar

* add screen reader text for avatar

* add slide-down animation on account switcher close

* remove comment

* setup account component story

* add all stories

* move navigation call to account component

* implement account lock

* add button hover effect

* implement account logout

* implement lockAll accounts functionality

* replace 'any' with custom type

* add account switcher button to /home login page

* use <main> tag (enables scrolling)

* change temp server filler name

* temporarily remove server arg from account story

* don't show avatar on /home if no accounts, and don't show 'lock'/'logout' buttons if no currentAccount

* add translation and a11y to /home avatar

* add correct server url to account component

* add 'server' to AccountOption type

* Enabled account switching client-side feature flag.

* add slide-in transition to /account-switcher page

* change capitalization to reflect figma design

* make screen reader read active account email, address more capitalization

* fix web avatar misalignment

* make avatar color based on user settings and in sync with other clients

* make property private

* change accountOptions to availableAccounts for clarity

* refactor to remove 'else' template ref

* remove empty scss rule

* use tailwind instead of scss

* rename isSelected to isActive

* add 'isButton' to /home page avatar

* move files to services folder

* update import

* Remove duplicate active account button

* Move no account button to current-account component

* Always complete logging out

Fixes PM-4866

* make screenreader read off email, not name

* refactor avatar for button case

* Do not next object updates

StateService's init was calling `updateState` at multiple layers,
once overall and then again for each account updated. Because
we were not maintaining a single state object through the
process, it was ending up in a consistent, but incomplete state.
Fixed by returning the updated state everywhere. This very well
may not be all the bugs associated with this

* Treat null switch account as no active user

* Listen for switchAccountFinish before routing (#6950)

* adjust avatar style when wrapped in a button

* show alt text for favicon setting

* move stories to browser

* Send Finish Message on null

* Dynamically set active user when locking all

This is required because some user lock states are not recoverable after
process reload (those with logout timeout). This waits until reload is
occurring, then sets the next user appropriately

* Move Finished Message to Finally Block

Fix tests

* Drop problematic key migration

Fixes PM-4933. This was an instance of foreground/background collision
when writing state. We have several other fallbacks of clearing
these deprecated keys.

* Prefer location to homebrew router service

* Initialize account disk cache from background

Uses the `isRecoveredSession` bool to re-initialize foreground caches
from a background message. This avoids a lengthy first-read for
foregrounds

* PM-4865 - Browser Acct Switcher - only show lock btn for lockable accounts (#6991)

* Lock of active account first, when locking multiple.

Fixes PM-4996

* Fix linter

* Hide lock now for locked users (#7020)

* Hide lock now for locked users

* Prefer disabling button to removing

* Add tooltip to TDE without unlock method

* Load all auth states on state init (#7027)

This is a temporary fix until the owning services can update state
themselves. It uses the presence of an auto key to surmise unlocked
state on init. This is safe since it's run only once on extension start.

* Ps/pm 5004/add load to account switcher (#7032)

* Add load spinner to account switcher

* Remove ul list icons

* Properly size account switcher in popout

* [PM-5005] Prevent Double Navigation (#7035)

* Delete Overriden Method

* Add Lock Transition

* truncate email and server name

* remove account.stories.ts (will add in separate PR)

* Do not switch user at reload if no user is active

* fix prettier issues

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
2023-12-06 09:22:48 -08:00
renovate[bot] 28de9439be
[deps] Autofill: Update prettier to v3 (#7014)
* [deps] Autofill: Update prettier to v3

* prettier formatting updates

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Prusik <jprusik@classynemesis.com>
2023-11-29 16:15:20 -05:00
Matt Gibson 7a7fe08a32
Ps/pm 2910/handle switch messaging (#6823)
* Handle switch messaging

TODO: handle loading state for account switcher

* Async updates required for state

* Fallback to email for current account avatar

* Await un-awaited promises

* Remove unnecessary Prune

Prune was getting confused in browser and deleting memory in browser on
account switch. This method isn't needed since logout already removes
memory data, which is the condition for pruning

* Fix temp password in browser

* Use direct memory access until data is serializable

Safari uses a different message object extraction than firefox/chrome
and is removing `UInt8Array`s. Until all data passed into StorageService
is guaranteed serializable, we need to use direct access in state
service

* Reload badge and context menu on switch

* Gracefully switch account as they log out.

* Maintain location on account switch

* Remove unused state definitions

* Prefer null for state

undefined can be misinterpreted to indicate a value has not been set.

* Hack: structured clone in memory storage

We are currently getting dead objects on account switch due to updating
the object in the foreground state service. However, the storage service
is owned by the background. This structured clone hack ensures that all
objects stored in memory are owned by the appropriate context

* Null check nullable values

active account can be null, so we should include null safety in the
equality

* Correct background->foreground switch command

* Already providing background memory storage

* Handle connection and clipboard on switch account

* Prefer strict equal

* Ensure structuredClone is available to jsdom

This is a deficiency in jsdom --
https://github.com/jsdom/jsdom/issues/3363 -- structured clone is well
supported.

* Fixup types in faker class
2023-11-29 09:59:50 -05:00