mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
[PM-21546] Migrate from enum to constant object (#14975)
* add generic `union-of-values` helper * migrate `GeneratorDialogAction` to a constant * migrate `VaultState` to a constant * migrate `AtRiskCarouselDialogResult` to a constant * migrate `CredentialGeneratorDialogAction` to a constant * migrate `FolderAddEditDialogResult` to a constant * migrate `ViewCipherDialogResult` to a constant * migrate `VisibleVaultBanner` to a constant * migrate `VaultFilterLabel` to a constant * migrate `WebVaultGeneratorDialogResult` to a constant * migrate `BulkDeleteDialogResult` to a constant * migrate `BulkMoveDialogResult` to a constant * migrate `AddEditCipherDialogResult` to a constant * migrate `VaultItemDialogResult` to a constant * migrate `BrowserPromptState` to a constant * migrate `NudgeType` to a constant * migrate `SecurityTaskStatus` to a constant * migrate `CipherRepromptType` to a constant * migrate `SecureNoteType` to a constant * migrate `FieldType` to a constant * migrate `LinkedIdType` to a constant * migrate `CollectionAssignmentResult` to a constant * migrate `AddEditFolderDialogResult` to a constant * migrate `AttachmentDialogResult` to a constant * fix CipherType in delete organization dialog * fix `in` statement in VaultFilter * Fix build errors across enum updates * fix two more CipherType castings * update CipherResponse `CipherType` * define type for `fieldType` parameter * refine how `cipherTypeNames` is generated and add utility function for grabbing cipher type name * use `CipherType` rather than `number` * add stricter typing for `FieldType` * add fixme for `CipherType` to be ADR-0025 compliant * remove error throw for `toCipherTypeName` and instead update typing to have `| undefined` * add helpers for CipherType conversions * prefer `undefined`
This commit is contained in:
@@ -18,7 +18,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherType, toCipherTypeName } from "@bitwarden/common/vault/enums";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
@@ -162,7 +162,7 @@ export class DeleteOrganizationDialogComponent implements OnInit, OnDestroy {
|
||||
organizationContentSummary.itemCountByType.push(
|
||||
new OrganizationContentSummaryItem(
|
||||
count,
|
||||
this.getOrganizationItemLocalizationKeysByType(CipherType[cipherType]),
|
||||
this.getOrganizationItemLocalizationKeysByType(toCipherTypeName(cipherType)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ describe("BrowserExtensionPromptComponent", () => {
|
||||
let component: BrowserExtensionPromptComponent;
|
||||
const start = jest.fn();
|
||||
const openExtension = jest.fn();
|
||||
const pageState$ = new BehaviorSubject(BrowserPromptState.Loading);
|
||||
const pageState$ = new BehaviorSubject<BrowserPromptState>(BrowserPromptState.Loading);
|
||||
const setAttribute = jest.fn();
|
||||
const getAttribute = jest.fn().mockReturnValue("width=1010");
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data";
|
||||
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogRef,
|
||||
@@ -95,29 +96,29 @@ export interface VaultItemDialogParams {
|
||||
restore?: (c: CipherView) => Promise<boolean>;
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum VaultItemDialogResult {
|
||||
export const VaultItemDialogResult = {
|
||||
/**
|
||||
* A cipher was saved (created or updated).
|
||||
*/
|
||||
Saved = "saved",
|
||||
Saved: "saved",
|
||||
|
||||
/**
|
||||
* A cipher was deleted.
|
||||
*/
|
||||
Deleted = "deleted",
|
||||
Deleted: "deleted",
|
||||
|
||||
/**
|
||||
* The dialog was closed to navigate the user the premium upgrade page.
|
||||
*/
|
||||
PremiumUpgrade = "premiumUpgrade",
|
||||
PremiumUpgrade: "premiumUpgrade",
|
||||
|
||||
/**
|
||||
* A cipher was restored
|
||||
*/
|
||||
Restored = "restored",
|
||||
}
|
||||
Restored: "restored",
|
||||
} as const;
|
||||
|
||||
export type VaultItemDialogResult = UnionOfValues<typeof VaultItemDialogResult>;
|
||||
|
||||
@Component({
|
||||
selector: "app-vault-item-dialog",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { CommonModule } from "@angular/common";
|
||||
import { Component, Inject } from "@angular/core";
|
||||
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogConfig,
|
||||
@@ -26,12 +27,12 @@ export interface WebVaultGeneratorDialogResult {
|
||||
generatedValue?: string;
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum WebVaultGeneratorDialogAction {
|
||||
Selected = "selected",
|
||||
Canceled = "canceled",
|
||||
}
|
||||
export const WebVaultGeneratorDialogAction = {
|
||||
Selected: "selected",
|
||||
Canceled: "canceled",
|
||||
} as const;
|
||||
|
||||
type WebVaultGeneratorDialogAction = UnionOfValues<typeof WebVaultGeneratorDialogAction>;
|
||||
|
||||
@Component({
|
||||
selector: "web-vault-generator-dialog",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
||||
import { CipherId, OrganizationId } from "@bitwarden/common/types/guid";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogConfig,
|
||||
@@ -35,13 +36,13 @@ import { WebCipherFormGenerationService } from "../services/web-cipher-form-gene
|
||||
/**
|
||||
* The result of the AddEditCipherDialogV2 component.
|
||||
*/
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum AddEditCipherDialogResult {
|
||||
Edited = "edited",
|
||||
Added = "added",
|
||||
Canceled = "canceled",
|
||||
}
|
||||
export const AddEditCipherDialogResult = {
|
||||
Edited: "edited",
|
||||
Added: "added",
|
||||
Canceled: "canceled",
|
||||
} as const;
|
||||
|
||||
type AddEditCipherDialogResult = UnionOfValues<typeof AddEditCipherDialogResult>;
|
||||
|
||||
/**
|
||||
* The close result of the AddEditCipherDialogV2 component.
|
||||
|
||||
@@ -12,6 +12,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherBulkDeleteRequest } from "@bitwarden/common/vault/models/request/cipher-bulk-delete.request";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogConfig,
|
||||
@@ -29,12 +30,12 @@ export interface BulkDeleteDialogParams {
|
||||
unassignedCiphers?: string[];
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum BulkDeleteDialogResult {
|
||||
Deleted = "deleted",
|
||||
Canceled = "canceled",
|
||||
}
|
||||
export const BulkDeleteDialogResult = {
|
||||
Deleted: "deleted",
|
||||
Canceled: "canceled",
|
||||
} as const;
|
||||
|
||||
type BulkDeleteDialogResult = UnionOfValues<typeof BulkDeleteDialogResult>;
|
||||
|
||||
/**
|
||||
* Strongly typed helper to open a BulkDeleteDialog
|
||||
|
||||
@@ -11,6 +11,7 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DialogConfig,
|
||||
DialogRef,
|
||||
@@ -23,12 +24,12 @@ export interface BulkMoveDialogParams {
|
||||
cipherIds?: string[];
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum BulkMoveDialogResult {
|
||||
Moved = "moved",
|
||||
Canceled = "canceled",
|
||||
}
|
||||
export const BulkMoveDialogResult = {
|
||||
Moved: "moved",
|
||||
Canceled: "canceled",
|
||||
} as const;
|
||||
|
||||
type BulkMoveDialogResult = UnionOfValues<typeof BulkMoveDialogResult>;
|
||||
|
||||
/**
|
||||
* Strongly typed helper to open a BulkMoveDialog
|
||||
|
||||
@@ -11,6 +11,7 @@ import { LogService } from "@bitwarden/common/platform/abstractions/log.service"
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogConfig,
|
||||
@@ -114,13 +115,13 @@ export interface FolderAddEditDialogParams {
|
||||
folderId: string;
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum FolderAddEditDialogResult {
|
||||
Deleted = "deleted",
|
||||
Canceled = "canceled",
|
||||
Saved = "saved",
|
||||
}
|
||||
export const FolderAddEditDialogResult = {
|
||||
Deleted: "deleted",
|
||||
Canceled: "canceled",
|
||||
Saved: "saved",
|
||||
} as const;
|
||||
|
||||
export type FolderAddEditDialogResult = UnionOfValues<typeof FolderAddEditDialogResult>;
|
||||
|
||||
/**
|
||||
* Strongly typed helper to open a FolderAddEdit dialog
|
||||
|
||||
@@ -15,17 +15,18 @@ import {
|
||||
} from "@bitwarden/common/platform/state";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import { PBKDF2KdfConfig, KdfConfigService, KdfType } from "@bitwarden/key-management";
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum VisibleVaultBanner {
|
||||
KDFSettings = "kdf-settings",
|
||||
OutdatedBrowser = "outdated-browser",
|
||||
Premium = "premium",
|
||||
VerifyEmail = "verify-email",
|
||||
PendingAuthRequest = "pending-auth-request",
|
||||
}
|
||||
export const VisibleVaultBanner = {
|
||||
KDFSettings: "kdf-settings",
|
||||
OutdatedBrowser: "outdated-browser",
|
||||
Premium: "premium",
|
||||
VerifyEmail: "verify-email",
|
||||
PendingAuthRequest: "pending-auth-request",
|
||||
} as const;
|
||||
|
||||
export type VisibleVaultBanner = UnionOfValues<typeof VisibleVaultBanner>;
|
||||
|
||||
type PremiumBannerReprompt = {
|
||||
numberOfDismissals: number;
|
||||
@@ -34,7 +35,7 @@ type PremiumBannerReprompt = {
|
||||
};
|
||||
|
||||
/** Banners that will be re-shown on a new session */
|
||||
type SessionBanners = Omit<VisibleVaultBanner, VisibleVaultBanner.Premium>;
|
||||
type SessionBanners = Omit<VisibleVaultBanner, typeof VisibleVaultBanner.Premium>;
|
||||
|
||||
export const PREMIUM_BANNER_REPROMPT_KEY = new UserKeyDefinition<PremiumBannerReprompt>(
|
||||
PREMIUM_BANNER_DISK_LOCAL,
|
||||
|
||||
@@ -98,7 +98,7 @@ export class VaultBannersComponent implements OnInit {
|
||||
showVerifyEmail ? VisibleVaultBanner.VerifyEmail : null,
|
||||
showLowKdf ? VisibleVaultBanner.KDFSettings : null,
|
||||
showPendingAuthRequest ? VisibleVaultBanner.PendingAuthRequest : null,
|
||||
].filter((banner): banner is VisibleVaultBanner => banner !== null); // ensures the filtered array contains only VisibleVaultBanner values
|
||||
].filter((banner) => banner !== null);
|
||||
}
|
||||
|
||||
freeTrialMessage(organization: FreeTrial) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { TreeNode } from "@bitwarden/common/vault/models/domain/tree-node";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
|
||||
import {
|
||||
CipherTypeFilter,
|
||||
@@ -15,15 +16,15 @@ export type VaultFilterType =
|
||||
| FolderFilter
|
||||
| CollectionFilter;
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum VaultFilterLabel {
|
||||
OrganizationFilter = "organizationFilter",
|
||||
TypeFilter = "typeFilter",
|
||||
FolderFilter = "folderFilter",
|
||||
CollectionFilter = "collectionFilter",
|
||||
TrashFilter = "trashFilter",
|
||||
}
|
||||
export const VaultFilterLabel = {
|
||||
OrganizationFilter: "organizationFilter",
|
||||
TypeFilter: "typeFilter",
|
||||
FolderFilter: "folderFilter",
|
||||
CollectionFilter: "collectionFilter",
|
||||
TrashFilter: "trashFilter",
|
||||
} as const;
|
||||
|
||||
type VaultFilterLabel = UnionOfValues<typeof VaultFilterLabel>;
|
||||
|
||||
export type VaultFilterSection = {
|
||||
data$: Observable<TreeNode<VaultFilterType>>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { CipherType, isCipherType } from "@bitwarden/common/vault/enums";
|
||||
import { TreeNode } from "@bitwarden/common/vault/models/domain/tree-node";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
|
||||
@@ -77,8 +77,8 @@ export class VaultFilter {
|
||||
}
|
||||
|
||||
get cipherType(): CipherType {
|
||||
return this.selectedCipherTypeNode?.node.type in CipherType
|
||||
? (this.selectedCipherTypeNode?.node.type as CipherType)
|
||||
return isCipherType(this.selectedCipherTypeNode?.node.type)
|
||||
? this.selectedCipherTypeNode?.node.type
|
||||
: null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import { ViewPasswordHistoryService } from "@bitwarden/common/vault/abstractions
|
||||
import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
import {
|
||||
DIALOG_DATA,
|
||||
DialogRef,
|
||||
@@ -54,13 +55,13 @@ export interface ViewCipherDialogParams {
|
||||
disableEdit?: boolean;
|
||||
}
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum ViewCipherDialogResult {
|
||||
Edited = "edited",
|
||||
Deleted = "deleted",
|
||||
PremiumUpgrade = "premiumUpgrade",
|
||||
}
|
||||
export const ViewCipherDialogResult = {
|
||||
Edited: "edited",
|
||||
Deleted: "deleted",
|
||||
PremiumUpgrade: "premiumUpgrade",
|
||||
} as const;
|
||||
|
||||
type ViewCipherDialogResult = UnionOfValues<typeof ViewCipherDialogResult>;
|
||||
|
||||
export interface ViewCipherDialogCloseResult {
|
||||
action: ViewCipherDialogResult;
|
||||
|
||||
@@ -6,18 +6,19 @@ import { AnonLayoutWrapperDataService } from "@bitwarden/auth/angular";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { VaultMessages } from "@bitwarden/common/vault/enums/vault-messages.enum";
|
||||
import { UnionOfValues } from "@bitwarden/common/vault/types/union-of-values";
|
||||
|
||||
// FIXME: update to use a const object instead of a typescript enum
|
||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
||||
export enum BrowserPromptState {
|
||||
Loading = "loading",
|
||||
Error = "error",
|
||||
Success = "success",
|
||||
ManualOpen = "manualOpen",
|
||||
MobileBrowser = "mobileBrowser",
|
||||
}
|
||||
export const BrowserPromptState = {
|
||||
Loading: "loading",
|
||||
Error: "error",
|
||||
Success: "success",
|
||||
ManualOpen: "manualOpen",
|
||||
MobileBrowser: "mobileBrowser",
|
||||
} as const;
|
||||
|
||||
type PromptErrorStates = BrowserPromptState.Error | BrowserPromptState.ManualOpen;
|
||||
export type BrowserPromptState = UnionOfValues<typeof BrowserPromptState>;
|
||||
|
||||
type PromptErrorStates = typeof BrowserPromptState.Error | typeof BrowserPromptState.ManualOpen;
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
|
||||
Reference in New Issue
Block a user