1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-30 22:41:33 +01:00

Merge branch 'main' into autofill/pm-5189-fix-issues-present-with-inline-menu-rendering-in-iframes

This commit is contained in:
Cesar Gonzalez 2024-04-08 11:06:55 -05:00
commit ea6e72da92
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
42 changed files with 385 additions and 175 deletions

View File

@ -38,9 +38,7 @@ const config: StorybookConfig = {
},
env: (config) => ({
...config,
FLAGS: JSON.stringify({
secretsManager: true,
}),
FLAGS: JSON.stringify({}),
}),
webpackFinal: async (config, { configType }) => {
if (config.resolve) {

View File

@ -17,7 +17,7 @@ import { CipherService } from "@bitwarden/common/vault/services/cipher.service";
import { FolderService } from "@bitwarden/common/vault/services/folder/folder.service";
import { BrowserApi } from "../../platform/browser/browser-api";
import { BrowserStateService } from "../../platform/services/browser-state.service";
import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service";
import { NotificationQueueMessageType } from "../enums/notification-queue-message-type.enum";
import { FormData } from "../services/abstractions/autofill.service";
import AutofillService from "../services/autofill.service";
@ -49,7 +49,7 @@ describe("NotificationBackground", () => {
const authService = mock<AuthService>();
const policyService = mock<PolicyService>();
const folderService = mock<FolderService>();
const stateService = mock<BrowserStateService>();
const stateService = mock<DefaultBrowserStateService>();
const userNotificationSettingsService = mock<UserNotificationSettingsService>();
const domainSettingsService = mock<DomainSettingsService>();
const environmentService = mock<EnvironmentService>();

View File

@ -34,7 +34,7 @@ import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { CipherService } from "@bitwarden/common/vault/services/cipher.service";
import { BrowserApi } from "../../platform/browser/browser-api";
import { BrowserStateService } from "../../platform/services/browser-state.service";
import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service";
import { BrowserPlatformUtilsService } from "../../platform/services/platform-utils/browser-platform-utils.service";
import { AutofillService } from "../services/abstractions/autofill.service";
import {
@ -77,7 +77,7 @@ describe("OverlayBackground", () => {
urls: { icons: "https://icons.bitwarden.com/" },
}),
);
const stateService = mock<BrowserStateService>();
const stateService = mock<DefaultBrowserStateService>();
const autofillSettingsService = mock<AutofillSettingsService>();
const i18nService = mock<I18nService>();
const platformUtilsService = mock<BrowserPlatformUtilsService>();

View File

@ -211,7 +211,7 @@ import BrowserLocalStorageService from "../platform/services/browser-local-stora
import BrowserMemoryStorageService from "../platform/services/browser-memory-storage.service";
import BrowserMessagingPrivateModeBackgroundService from "../platform/services/browser-messaging-private-mode-background.service";
import BrowserMessagingService from "../platform/services/browser-messaging.service";
import { BrowserStateService } from "../platform/services/browser-state.service";
import { DefaultBrowserStateService } from "../platform/services/default-browser-state.service";
import I18nService from "../platform/services/i18n.service";
import { LocalBackedSessionStorageService } from "../platform/services/local-backed-session-storage.service";
import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service";
@ -466,7 +466,7 @@ export default class MainBackground {
new MigrationBuilderService(),
);
this.stateService = new BrowserStateService(
this.stateService = new DefaultBrowserStateService(
this.storageService,
this.secureStorageService,
this.memoryStorageService,

View File

@ -10,7 +10,7 @@ import {
TokenServiceInitOptions,
} from "../../../auth/background/service-factories/token-service.factory";
import { Account } from "../../../models/account";
import { BrowserStateService } from "../../services/browser-state.service";
import { DefaultBrowserStateService } from "../../services/default-browser-state.service";
import {
environmentServiceFactory,
@ -46,15 +46,15 @@ export type StateServiceInitOptions = StateServiceFactoryOptions &
MigrationRunnerInitOptions;
export async function stateServiceFactory(
cache: { stateService?: BrowserStateService } & CachedServices,
cache: { stateService?: DefaultBrowserStateService } & CachedServices,
opts: StateServiceInitOptions,
): Promise<BrowserStateService> {
): Promise<DefaultBrowserStateService> {
const service = await factory(
cache,
"stateService",
opts,
async () =>
new BrowserStateService(
new DefaultBrowserStateService(
await diskStorageServiceFactory(cache, opts),
await secureStorageServiceFactory(cache, opts),
await memoryStorageServiceFactory(cache, opts),

View File

@ -3,7 +3,7 @@ import { BehaviorSubject } from "rxjs";
import { AbstractMemoryStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
import { BrowserStateService } from "../../services/browser-state.service";
import { DefaultBrowserStateService } from "../../services/default-browser-state.service";
import { browserSession } from "./browser-session.decorator";
import { SessionStorable } from "./session-storable";
@ -25,7 +25,7 @@ describe("browserSession decorator", () => {
});
it("should create if StateService is a constructor argument", () => {
const stateService = Object.create(BrowserStateService.prototype, {
const stateService = Object.create(DefaultBrowserStateService.prototype, {
memoryStorageService: {
value: Object.create(MemoryStorageService.prototype, {
type: { value: MemoryStorageService.TYPE },
@ -35,7 +35,7 @@ describe("browserSession decorator", () => {
@browserSession
class TestClass {
constructor(private stateService: BrowserStateService) {}
constructor(private stateService: DefaultBrowserStateService) {}
}
expect(new TestClass(stateService)).toBeDefined();

View File

@ -11,13 +11,13 @@ import { GroupPolicyEnvironment } from "../admin-console/types/group-policy-envi
import { BrowserApi } from "./browser/browser-api";
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type Flags = {
accountSwitching?: boolean;
} & SharedFlags;
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type DevFlags = {
storeSessionDecrypted?: boolean;
managedEnvironment?: GroupPolicyEnvironment;

View File

@ -8,6 +8,23 @@ import {
import { fromChromeEvent } from "../../browser/from-chrome-event";
export const serializationIndicator = "__json__";
export const objToStore = (obj: any) => {
if (obj == null) {
return null;
}
if (obj instanceof Set) {
obj = Array.from(obj);
}
return {
[serializationIndicator]: true,
value: JSON.stringify(obj),
};
};
export default abstract class AbstractChromeStorageService
implements AbstractStorageService, ObservableStorageService
{
@ -44,7 +61,11 @@ export default abstract class AbstractChromeStorageService
return new Promise((resolve) => {
this.chromeStorageApi.get(key, (obj: any) => {
if (obj != null && obj[key] != null) {
resolve(obj[key] as T);
let value = obj[key];
if (value[serializationIndicator] && typeof value.value === "string") {
value = JSON.parse(value.value);
}
resolve(value as T);
return;
}
resolve(null);
@ -57,14 +78,7 @@ export default abstract class AbstractChromeStorageService
}
async save(key: string, obj: any): Promise<void> {
if (obj == null) {
// Fix safari not liking null in set
return this.remove(key);
}
if (obj instanceof Set) {
obj = Array.from(obj);
}
obj = objToStore(obj);
const keyedObj = { [key]: obj };
return new Promise<void>((resolve) => {

View File

@ -1,19 +1,5 @@
import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options";
import { Account } from "../../../models/account";
import { BrowserComponentState } from "../../../models/browserComponentState";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
export abstract class BrowserStateService extends BaseStateServiceAbstraction<Account> {
getBrowserSendComponentState: (options?: StorageOptions) => Promise<BrowserSendComponentState>;
setBrowserSendComponentState: (
value: BrowserSendComponentState,
options?: StorageOptions,
) => Promise<void>;
getBrowserSendTypeComponentState: (options?: StorageOptions) => Promise<BrowserComponentState>;
setBrowserSendTypeComponentState: (
value: BrowserComponentState,
options?: StorageOptions,
) => Promise<void>;
}
export abstract class BrowserStateService extends BaseStateServiceAbstraction<Account> {}

View File

@ -0,0 +1,99 @@
import AbstractChromeStorageService, {
objToStore,
serializationIndicator,
} from "./abstract-chrome-storage-api.service";
class TestChromeStorageApiService extends AbstractChromeStorageService {}
describe("objectToStore", () => {
it("converts an object to a tagged string", () => {
const obj = { key: "value" };
const result = objToStore(obj);
expect(result).toEqual({
[serializationIndicator]: true,
value: JSON.stringify(obj),
});
});
it("converts a set to an array prior to serialization", () => {
const obj = new Set(["value"]);
const result = objToStore(obj);
expect(result).toEqual({
[serializationIndicator]: true,
value: JSON.stringify(Array.from(obj)),
});
});
it("does nothing to null", () => {
expect(objToStore(null)).toEqual(null);
});
});
describe("ChromeStorageApiService", () => {
let service: TestChromeStorageApiService;
let store: Record<any, any>;
beforeEach(() => {
store = {};
service = new TestChromeStorageApiService(chrome.storage.local);
});
describe("save", () => {
let setMock: jest.Mock;
beforeEach(() => {
// setup save
setMock = chrome.storage.local.set as jest.Mock;
setMock.mockImplementation((data, callback) => {
Object.assign(store, data);
callback();
});
});
it("uses `objToStore` to prepare a value for set", async () => {
const key = "key";
const value = { key: "value" };
await service.save(key, value);
expect(setMock).toHaveBeenCalledWith(
{
[key]: objToStore(value),
},
expect.any(Function),
);
});
});
describe("get", () => {
let getMock: jest.Mock;
beforeEach(() => {
// setup get
getMock = chrome.storage.local.get as jest.Mock;
getMock.mockImplementation((key, callback) => {
callback({ [key]: store[key] });
});
});
it("returns a stored value when it is serialized", async () => {
const key = "key";
const value = { key: "value" };
store[key] = objToStore(value);
const result = await service.get(key);
expect(result).toEqual(value);
});
it("returns a stored value when it is not serialized", async () => {
const key = "key";
const value = "value";
store[key] = value;
const result = await service.get(key);
expect(result).toEqual(value);
});
it("returns null when the key does not exist", async () => {
const result = await service.get("key");
expect(result).toBeNull();
});
});
});

View File

@ -1,4 +1,5 @@
import { mock, MockProxy } from "jest-mock-extended";
import { firstValueFrom } from "rxjs";
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
@ -12,15 +13,11 @@ import { GlobalState } from "@bitwarden/common/platform/models/domain/global-sta
import { State } from "@bitwarden/common/platform/models/domain/state";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
import { mockAccountServiceWith } from "@bitwarden/common/spec";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { UserId } from "@bitwarden/common/types/guid";
import { Account } from "../../models/account";
import { BrowserComponentState } from "../../models/browserComponentState";
import { BrowserSendComponentState } from "../../models/browserSendComponentState";
import { BrowserStateService } from "./browser-state.service";
import { DefaultBrowserStateService } from "./default-browser-state.service";
// disable session syncing to just test class
jest.mock("../decorators/session-sync-observable/");
@ -39,7 +36,7 @@ describe("Browser State Service", () => {
const userId = "userId" as UserId;
const accountService = mockAccountServiceWith(userId);
let sut: BrowserStateService;
let sut: DefaultBrowserStateService;
beforeEach(() => {
secureStorageService = mock();
@ -71,7 +68,7 @@ describe("Browser State Service", () => {
const stateGetter = (key: string) => Promise.resolve(state);
memoryStorageService.get.mockImplementation(stateGetter);
sut = new BrowserStateService(
sut = new DefaultBrowserStateService(
diskStorageService,
secureStorageService,
memoryStorageService,
@ -85,32 +82,17 @@ describe("Browser State Service", () => {
);
});
describe("getBrowserSendComponentState", () => {
it("should return a BrowserSendComponentState", async () => {
const sendState = new BrowserSendComponentState();
sendState.sends = [new SendView(), new SendView()];
sendState.typeCounts = new Map<SendType, number>([
[SendType.File, 3],
[SendType.Text, 5],
]);
state.accounts[userId].send = sendState;
(global as any)["watch"] = state;
describe("add Account", () => {
it("should add account", async () => {
const newUserId = "newUserId" as UserId;
const newAcct = new Account({
profile: { userId: newUserId },
});
const actual = await sut.getBrowserSendComponentState();
expect(actual).toBeInstanceOf(BrowserSendComponentState);
expect(actual).toMatchObject(sendState);
});
});
await sut.addAccount(newAcct);
describe("getBrowserSendTypeComponentState", () => {
it("should return a BrowserComponentState", async () => {
const componentState = new BrowserComponentState();
componentState.scrollY = 0;
componentState.searchText = "test";
state.accounts[userId].sendType = componentState;
const actual = await sut.getBrowserSendTypeComponentState();
expect(actual).toStrictEqual(componentState);
const accts = await firstValueFrom(sut.accounts$);
expect(accts[newUserId]).toBeDefined();
});
});
});

View File

@ -15,17 +15,15 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r
import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service";
import { Account } from "../../models/account";
import { BrowserComponentState } from "../../models/browserComponentState";
import { BrowserSendComponentState } from "../../models/browserSendComponentState";
import { BrowserApi } from "../browser/browser-api";
import { browserSession, sessionSync } from "../decorators/session-sync-observable";
import { BrowserStateService as StateServiceAbstraction } from "./abstractions/browser-state.service";
import { BrowserStateService } from "./abstractions/browser-state.service";
@browserSession
export class BrowserStateService
export class DefaultBrowserStateService
extends BaseStateService<GlobalState, Account>
implements StateServiceAbstraction
implements BrowserStateService
{
@sessionSync({
initializer: Account.fromJSON as any, // TODO: Remove this any when all any types are removed from Account
@ -115,46 +113,6 @@ export class BrowserStateService
);
}
async getBrowserSendComponentState(options?: StorageOptions): Promise<BrowserSendComponentState> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
)?.send;
}
async setBrowserSendComponentState(
value: BrowserSendComponentState,
options?: StorageOptions,
): Promise<void> {
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
account.send = value;
await this.saveAccount(
account,
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
}
async getBrowserSendTypeComponentState(options?: StorageOptions): Promise<BrowserComponentState> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
)?.sendType;
}
async setBrowserSendTypeComponentState(
value: BrowserComponentState,
options?: StorageOptions,
): Promise<void> {
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
account.sendType = value;
await this.saveAccount(
account,
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
}
// Overriding the base class to prevent deleting the cache on save. We register a storage listener
// to delete the cache in the constructor above.
protected override async saveAccountToDisk(

View File

@ -12,6 +12,7 @@ import { BrowserApi } from "../platform/browser/browser-api";
import { ZonedMessageListenerService } from "../platform/browser/zoned-message-listener.service";
import { BrowserStateService } from "../platform/services/abstractions/browser-state.service";
import { ForegroundPlatformUtilsService } from "../platform/services/platform-utils/foreground-platform-utils.service";
import { BrowserSendStateService } from "../tools/popup/services/browser-send-state.service";
import { VaultBrowserStateService } from "../vault/services/vault-browser-state.service";
import { routerTransition } from "./app-routing.animations";
@ -38,6 +39,7 @@ export class AppComponent implements OnInit, OnDestroy {
private i18nService: I18nService,
private router: Router,
private stateService: BrowserStateService,
private browserSendStateService: BrowserSendStateService,
private vaultBrowserStateService: VaultBrowserStateService,
private changeDetectorRef: ChangeDetectorRef,
private ngZone: NgZone,
@ -231,8 +233,8 @@ export class AppComponent implements OnInit, OnDestroy {
await Promise.all([
this.vaultBrowserStateService.setBrowserGroupingsComponentState(null),
this.vaultBrowserStateService.setBrowserVaultItemsComponentState(null),
this.stateService.setBrowserSendComponentState(null),
this.stateService.setBrowserSendTypeComponentState(null),
this.browserSendStateService.setBrowserSendComponentState(null),
this.browserSendStateService.setBrowserSendTypeComponentState(null),
]);
}
}

View File

@ -99,11 +99,12 @@ import { BrowserEnvironmentService } from "../../platform/services/browser-envir
import BrowserLocalStorageService from "../../platform/services/browser-local-storage.service";
import BrowserMessagingPrivateModePopupService from "../../platform/services/browser-messaging-private-mode-popup.service";
import BrowserMessagingService from "../../platform/services/browser-messaging.service";
import { BrowserStateService } from "../../platform/services/browser-state.service";
import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service";
import I18nService from "../../platform/services/i18n.service";
import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service";
import { ForegroundDerivedStateProvider } from "../../platform/state/foreground-derived-state.provider";
import { ForegroundMemoryStorageService } from "../../platform/storage/foreground-memory-storage.service";
import { BrowserSendStateService } from "../../tools/popup/services/browser-send-state.service";
import { FilePopoutUtilsService } from "../../tools/popup/services/file-popout-utils.service";
import { VaultBrowserStateService } from "../../vault/services/vault-browser-state.service";
import { VaultFilterService } from "../../vault/services/vault-filter.service";
@ -412,7 +413,7 @@ const safeProviders: SafeProvider[] = [
tokenService: TokenService,
migrationRunner: MigrationRunner,
) => {
return new BrowserStateService(
return new DefaultBrowserStateService(
storageService,
secureStorageService,
memoryStorageService,
@ -487,6 +488,11 @@ const safeProviders: SafeProvider[] = [
useClass: UserNotificationSettingsService,
deps: [StateProvider],
}),
safeProvider({
provide: BrowserSendStateService,
useClass: BrowserSendStateService,
deps: [StateProvider],
}),
];
@NgModule({

View File

@ -18,7 +18,7 @@ import { DialogService } from "@bitwarden/components";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
import { BrowserStateService } from "../../../platform/services/abstractions/browser-state.service";
import { BrowserSendStateService } from "../services/browser-send-state.service";
const ComponentId = "SendComponent";
@ -43,7 +43,7 @@ export class SendGroupingsComponent extends BaseSendComponent {
ngZone: NgZone,
policyService: PolicyService,
searchService: SearchService,
private stateService: BrowserStateService,
private stateService: BrowserSendStateService,
private router: Router,
private syncService: SyncService,
private changeDetectorRef: ChangeDetectorRef,

View File

@ -19,7 +19,7 @@ import { DialogService } from "@bitwarden/components";
import { BrowserComponentState } from "../../../models/browserComponentState";
import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils";
import { BrowserStateService } from "../../../platform/services/abstractions/browser-state.service";
import { BrowserSendStateService } from "../services/browser-send-state.service";
const ComponentId = "SendTypeComponent";
@ -42,7 +42,7 @@ export class SendTypeComponent extends BaseSendComponent {
ngZone: NgZone,
policyService: PolicyService,
searchService: SearchService,
private stateService: BrowserStateService,
private stateService: BrowserSendStateService,
private route: ActivatedRoute,
private location: Location,
private changeDetectorRef: ChangeDetectorRef,

View File

@ -0,0 +1,61 @@
import {
FakeAccountService,
mockAccountServiceWith,
} from "@bitwarden/common/../spec/fake-account-service";
import { FakeStateProvider } from "@bitwarden/common/../spec/fake-state-provider";
import { awaitAsync } from "@bitwarden/common/../spec/utils";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { UserId } from "@bitwarden/common/types/guid";
import { BrowserComponentState } from "../../../models/browserComponentState";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
import { BrowserSendStateService } from "./browser-send-state.service";
describe("Browser Send State Service", () => {
let stateProvider: FakeStateProvider;
let accountService: FakeAccountService;
let stateService: BrowserSendStateService;
const mockUserId = Utils.newGuid() as UserId;
beforeEach(() => {
accountService = mockAccountServiceWith(mockUserId);
stateProvider = new FakeStateProvider(accountService);
stateService = new BrowserSendStateService(stateProvider);
});
describe("getBrowserSendComponentState", () => {
it("should return BrowserSendComponentState", async () => {
const state = new BrowserSendComponentState();
state.scrollY = 0;
state.searchText = "test";
state.typeCounts = new Map<SendType, number>().set(SendType.File, 1);
await stateService.setBrowserSendComponentState(state);
await awaitAsync();
const actual = await stateService.getBrowserSendComponentState();
expect(actual).toStrictEqual(state);
});
});
describe("getBrowserSendTypeComponentState", () => {
it("should return BrowserComponentState", async () => {
const state = new BrowserComponentState();
state.scrollY = 0;
state.searchText = "test";
await stateService.setBrowserSendTypeComponentState(state);
await awaitAsync();
const actual = await stateService.getBrowserSendTypeComponentState();
expect(actual).toStrictEqual(state);
});
});
});

View File

@ -0,0 +1,65 @@
import { Observable, firstValueFrom } from "rxjs";
import { ActiveUserState, StateProvider } from "@bitwarden/common/platform/state";
import { BrowserComponentState } from "../../../models/browserComponentState";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
import { BROWSER_SEND_COMPONENT, BROWSER_SEND_TYPE_COMPONENT } from "./key-definitions";
/** Get or set the active user's component state for the Send browser component
*/
export class BrowserSendStateService {
/** Observable that contains the current state for active user Sends including the send data and type counts
* along with the search text and scroll position
*/
browserSendComponentState$: Observable<BrowserSendComponentState>;
/** Observable that contains the current state for active user Sends that only includes the search text
* and scroll position
*/
browserSendTypeComponentState$: Observable<BrowserComponentState>;
private activeUserBrowserSendComponentState: ActiveUserState<BrowserSendComponentState>;
private activeUserBrowserSendTypeComponentState: ActiveUserState<BrowserComponentState>;
constructor(protected stateProvider: StateProvider) {
this.activeUserBrowserSendComponentState = this.stateProvider.getActive(BROWSER_SEND_COMPONENT);
this.browserSendComponentState$ = this.activeUserBrowserSendComponentState.state$;
this.activeUserBrowserSendTypeComponentState = this.stateProvider.getActive(
BROWSER_SEND_TYPE_COMPONENT,
);
this.browserSendTypeComponentState$ = this.activeUserBrowserSendTypeComponentState.state$;
}
/** Get the active user's browser send component state
* @returns { BrowserSendComponentState } contains the sends and type counts along with the scroll position and search text for the
* send component on the browser
*/
async getBrowserSendComponentState(): Promise<BrowserSendComponentState> {
return await firstValueFrom(this.browserSendComponentState$);
}
/** Set the active user's browser send component state
* @param { BrowserSendComponentState } value sets the sends and type counts along with the scroll position and search text for
* the send component on the browser
*/
async setBrowserSendComponentState(value: BrowserSendComponentState): Promise<void> {
await this.activeUserBrowserSendComponentState.update(() => value);
}
/** Get the active user's browser component state
* @returns { BrowserComponentState } contains the scroll position and search text for the sends menu on the browser
*/
async getBrowserSendTypeComponentState(): Promise<BrowserComponentState> {
return await firstValueFrom(this.browserSendTypeComponentState$);
}
/** Set the active user's browser component state
* @param { BrowserComponentState } value set the scroll position and search text for the send component on the browser
*/
async setBrowserSendTypeComponentState(value: BrowserComponentState): Promise<void> {
await this.activeUserBrowserSendTypeComponentState.update(() => value);
}
}

View File

@ -0,0 +1,40 @@
import { Jsonify } from "type-fest";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
import { BROWSER_SEND_COMPONENT, BROWSER_SEND_TYPE_COMPONENT } from "./key-definitions";
describe("Key definitions", () => {
describe("BROWSER_SEND_COMPONENT", () => {
it("should deserialize BrowserSendComponentState", () => {
const keyDef = BROWSER_SEND_COMPONENT;
const expectedState = {
typeCounts: new Map<SendType, number>(),
};
const result = keyDef.deserializer(
JSON.parse(JSON.stringify(expectedState)) as Jsonify<BrowserSendComponentState>,
);
expect(result).toEqual(expectedState);
});
});
describe("BROWSER_SEND_TYPE_COMPONENT", () => {
it("should deserialize BrowserComponentState", () => {
const keyDef = BROWSER_SEND_TYPE_COMPONENT;
const expectedState = {
scrollY: 0,
searchText: "test",
};
const result = keyDef.deserializer(JSON.parse(JSON.stringify(expectedState)));
expect(result).toEqual(expectedState);
});
});
});

View File

@ -0,0 +1,23 @@
import { Jsonify } from "type-fest";
import { BROWSER_SEND_MEMORY, KeyDefinition } from "@bitwarden/common/platform/state";
import { BrowserComponentState } from "../../../models/browserComponentState";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
export const BROWSER_SEND_COMPONENT = new KeyDefinition<BrowserSendComponentState>(
BROWSER_SEND_MEMORY,
"browser_send_component",
{
deserializer: (obj: Jsonify<BrowserSendComponentState>) =>
BrowserSendComponentState.fromJSON(obj),
},
);
export const BROWSER_SEND_TYPE_COMPONENT = new KeyDefinition<BrowserComponentState>(
BROWSER_SEND_MEMORY,
"browser_send_type_component",
{
deserializer: (obj: Jsonify<BrowserComponentState>) => BrowserComponentState.fromJSON(obj),
},
);

View File

@ -7,11 +7,11 @@ import {
} from "@bitwarden/common/platform/misc/flags";
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type Flags = {} & SharedFlags;
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type DevFlags = {} & SharedDevFlags;
export function flagEnabled(flag: keyof Flags): boolean {

View File

@ -1,7 +1,6 @@
{
"devFlags": {},
"flags": {
"showDDGSetting": true,
"enableCipherKeyEncryption": false
}
}

View File

@ -1,6 +1,5 @@
{
"flags": {
"showDDGSetting": true,
"enableCipherKeyEncryption": false
}
}

View File

@ -24,7 +24,6 @@ import { DialogService } from "@bitwarden/components";
import { SetPinComponent } from "../../auth/components/set-pin.component";
import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service";
import { flagEnabled } from "../../platform/flags";
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
@Component({
@ -146,7 +145,7 @@ export class SettingsComponent implements OnInit {
this.startToTrayDescText = this.i18nService.t(startToTrayKey + "Desc");
// DuckDuckGo browser is only for macos initially
this.showDuckDuckGoIntegrationOption = flagEnabled("showDDGSetting") && isMac;
this.showDuckDuckGoIntegrationOption = isMac;
this.vaultTimeoutOptions = [
// { name: i18nService.t('immediately'), value: 0 },

View File

@ -7,13 +7,11 @@ import {
} from "@bitwarden/common/platform/misc/flags";
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
export type Flags = {
showDDGSetting?: boolean;
} & SharedFlags;
// eslint-disable-next-line @typescript-eslint/ban-types
export type Flags = {} & SharedFlags;
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type DevFlags = {} & SharedDevFlags;
export function flagEnabled(flag: keyof Flags): boolean {

View File

@ -11,7 +11,6 @@
"allowedHosts": "auto"
},
"flags": {
"secretsManager": false,
"showPasswordless": false,
"enableCipherKeyEncryption": false
}

View File

@ -17,7 +17,6 @@
"proxyNotifications": "https://notifications.bitwarden.com"
},
"flags": {
"secretsManager": true,
"showPasswordless": true,
"enableCipherKeyEncryption": false
}

View File

@ -20,7 +20,6 @@
}
],
"flags": {
"secretsManager": true,
"showPasswordless": true,
"enableCipherKeyEncryption": false
},

View File

@ -11,7 +11,6 @@
"buttonAction": "https://www.paypal.com/cgi-bin/webscr"
},
"flags": {
"secretsManager": true,
"showPasswordless": true,
"enableCipherKeyEncryption": false
}

View File

@ -21,7 +21,6 @@
}
],
"flags": {
"secretsManager": true,
"showPasswordless": true
}
}

View File

@ -27,7 +27,6 @@
}
],
"flags": {
"secretsManager": true,
"showPasswordless": true,
"enableCipherKeyEncryption": false
}

View File

@ -7,7 +7,6 @@
"port": 8081
},
"flags": {
"secretsManager": true,
"showPasswordless": true,
"enableCipherKeyEncryption": false
}

View File

@ -5,7 +5,6 @@
"scim": "https://scim.usdev.bitwarden.pw"
},
"flags": {
"secretsManager": true,
"showPasswordless": true
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@bitwarden/web-vault",
"version": "2024.3.1",
"version": "2024.4.0",
"scripts": {
"build:oss": "webpack",
"build:bit": "webpack -c ../../bitwarden_license/bit-web/webpack.config.js",
@ -8,7 +8,7 @@
"build:bit:watch": "webpack serve -c ../../bitwarden_license/bit-web/webpack.config.js",
"build:bit:dev": "cross-env ENV=development npm run build:bit",
"build:bit:dev:analyze": "cross-env LOGGING=false webpack -c ../../bitwarden_license/bit-web/webpack.config.js --profile --json > stats.json && npx webpack-bundle-analyzer stats.json build/",
"build:bit:dev:watch": "cross-env ENV=development npm run build:bit:watch",
"build:bit:dev:watch": "cross-env ENV=development NODE_OPTIONS=\"--max-old-space-size=8192\" npm run build:bit:watch",
"build:bit:qa": "cross-env NODE_ENV=production ENV=qa npm run build:bit",
"build:bit:euprd": "cross-env NODE_ENV=production ENV=euprd npm run build:bit",
"build:bit:euqa": "cross-env NODE_ENV=production ENV=euqa npm run build:bit",

View File

@ -52,7 +52,6 @@ import { Collection } from "@bitwarden/common/vault/models/domain/collection";
import { CollectionDetailsResponse } from "@bitwarden/common/vault/models/response/collection.response";
import { DialogService, SimpleDialogOptions } from "@bitwarden/components";
import { flagEnabled } from "../../../../utils/flags";
import { openEntityEventsDialog } from "../../../admin-console/organizations/manage/entity-events.component";
import { BasePeopleComponent } from "../../common/base.people.component";
import { GroupService } from "../core";
@ -148,9 +147,7 @@ export class PeopleComponent
shareReplay({ refCount: true, bufferSize: 1 }),
);
this.canUseSecretsManager$ = organization$.pipe(
map((org) => org.useSecretsManager && flagEnabled("secretsManager")),
);
this.canUseSecretsManager$ = organization$.pipe(map((org) => org.useSecretsManager));
const policies$ = organization$.pipe(
switchMap((organization) => {

View File

@ -1,10 +1,8 @@
<ng-template [ngIf]="isEnabled">
<button
type="button"
bitIconButton="bwi bwi-fw bwi-filter"
[bitMenuTriggerFor]="content?.menu"
[buttonType]="buttonType"
[attr.aria-label]="'switchProducts' | i18n"
></button>
<product-switcher-content #content></product-switcher-content>
</ng-template>
<button
type="button"
bitIconButton="bwi bwi-fw bwi-filter"
[bitMenuTriggerFor]="content?.menu"
[buttonType]="buttonType"
[attr.aria-label]="'switchProducts' | i18n"
></button>
<product-switcher-content #content></product-switcher-content>

View File

@ -1,16 +1,11 @@
import { AfterViewInit, ChangeDetectorRef, Component, Input } from "@angular/core";
import { IconButtonType } from "@bitwarden/components/src/icon-button/icon-button.component";
import { flagEnabled } from "../../../utils/flags";
@Component({
selector: "product-switcher",
templateUrl: "./product-switcher.component.html",
})
export class ProductSwitcherComponent implements AfterViewInit {
protected isEnabled = flagEnabled("secretsManager");
/**
* Passed to the product switcher's `bitIconButton`
*/

View File

@ -7,14 +7,13 @@ import {
} from "@bitwarden/common/platform/misc/flags";
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type Flags = {
secretsManager?: boolean;
showPasswordless?: boolean;
} & SharedFlags;
// required to avoid linting errors when there are no flags
/* eslint-disable-next-line @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type DevFlags = {} & SharedDevFlags;
export function flagEnabled(flag: keyof Flags): boolean {

View File

@ -2,7 +2,6 @@ import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { AuthGuard } from "@bitwarden/angular/auth/guards";
import { buildFlaggedRoute } from "@bitwarden/web-vault/app/oss-routing.module";
import { organizationEnabledGuard } from "./guards/sm-org-enabled.guard";
import { canActivateSM } from "./guards/sm.guard";
@ -17,7 +16,7 @@ import { OrgSuspendedComponent } from "./shared/org-suspended.component";
import { TrashModule } from "./trash/trash.module";
const routes: Routes = [
buildFlaggedRoute("secretsManager", {
{
path: "",
children: [
{
@ -86,7 +85,7 @@ const routes: Routes = [
],
},
],
}),
},
];
@NgModule({

View File

@ -1,5 +1,5 @@
// required to avoid linting errors when there are no flags
/* eslint-disable @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type SharedFlags = {
multithreadDecryption: boolean;
showPasswordless?: boolean;
@ -7,7 +7,7 @@ export type SharedFlags = {
};
// required to avoid linting errors when there are no flags
/* eslint-disable @typescript-eslint/ban-types */
// eslint-disable-next-line @typescript-eslint/ban-types
export type SharedDevFlags = {
noopNotifications: boolean;
};

View File

@ -102,6 +102,7 @@ export const SM_ONBOARDING_DISK = new StateDefinition("smOnboarding", "disk", {
export const GENERATOR_DISK = new StateDefinition("generator", "disk");
export const GENERATOR_MEMORY = new StateDefinition("generator", "memory");
export const BROWSER_SEND_MEMORY = new StateDefinition("sendBrowser", "memory");
export const EVENT_COLLECTION_DISK = new StateDefinition("eventCollection", "disk");
export const SEND_DISK = new StateDefinition("encryptedSend", "disk", {
web: "memory",

2
package-lock.json generated
View File

@ -247,7 +247,7 @@
},
"apps/web": {
"name": "@bitwarden/web-vault",
"version": "2024.3.1"
"version": "2024.4.0"
},
"libs/admin-console": {
"name": "@bitwarden/admin-console",