1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

PM-22143 Refactor TS enums to be const objects (Import only) (#16770)

* Import related changes from PR #16399
This commit is contained in:
John Harrington
2025-10-15 09:08:47 -07:00
committed by GitHub
parent 2858d12011
commit 76e4870aa3
9 changed files with 180 additions and 137 deletions

View File

@@ -1,5 +1,3 @@
// 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 } from "@bitwarden/common/vault/enums";
import { CardView } from "@bitwarden/common/vault/models/view/card.view"; import { CardView } from "@bitwarden/common/vault/models/view/card.view";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
@@ -8,7 +6,7 @@ import { ImportResult } from "../../models/import-result";
import { BaseImporter } from "../base-importer"; import { BaseImporter } from "../base-importer";
import { Importer } from "../importer"; import { Importer } from "../importer";
import { FskEntry, FskEntryTypesEnum, FskFile } from "./fsecure-fsk-types"; import { FskEntry, FskEntryType, FskFile } from "./fsecure-fsk-types";
export class FSecureFskImporter extends BaseImporter implements Importer { export class FSecureFskImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> { parse(data: string): Promise<ImportResult> {
@@ -19,37 +17,32 @@ export class FSecureFskImporter extends BaseImporter implements Importer {
return Promise.resolve(result); return Promise.resolve(result);
} }
for (const key in results.data) { for (const [, value] of Object.entries(results.data)) {
// eslint-disable-next-line
if (!results.data.hasOwnProperty(key)) {
continue;
}
const value = results.data[key];
const cipher = this.parseEntry(value); const cipher = this.parseEntry(value);
if (cipher != undefined) {
result.ciphers.push(cipher); result.ciphers.push(cipher);
} }
}
result.success = true; result.success = true;
return Promise.resolve(result); return Promise.resolve(result);
} }
private parseEntry(entry: FskEntry): CipherView { private parseEntry(entry: FskEntry): CipherView | undefined {
const cipher = this.initLoginCipher(); const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(entry.service); cipher.name = this.getValueOrDefault(entry.service);
cipher.notes = this.getValueOrDefault(entry.notes); cipher.notes = this.getValueOrDefault(entry.notes);
cipher.favorite = entry.favorite > 0; cipher.favorite = entry.favorite > 0;
switch (entry.type) { switch (entry.type) {
case FskEntryTypesEnum.Login: case FskEntryType.Login:
this.handleLoginEntry(entry, cipher); this.handleLoginEntry(entry, cipher);
break; break;
case FskEntryTypesEnum.CreditCard: case FskEntryType.CreditCard:
this.handleCreditCardEntry(entry, cipher); this.handleCreditCardEntry(entry, cipher);
break; break;
default: default:
return; return undefined;
break;
} }
this.convertToNoteIfNeeded(cipher); this.convertToNoteIfNeeded(cipher);

View File

@@ -6,12 +6,18 @@ export interface Data {
[key: string]: FskEntry; [key: string]: FskEntry;
} }
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents the different types of FSK entries.
export enum FskEntryTypesEnum { */
Login = 1, export const FskEntryType = Object.freeze({
CreditCard = 2, Login: 1,
} CreditCard: 2,
});
/**
* Type representing valid FSK entry type values.
*/
export type FskEntryType = (typeof FskEntryType)[keyof typeof FskEntryType];
export interface FskEntry { export interface FskEntry {
color: string; color: string;
@@ -26,7 +32,7 @@ export interface FskEntry {
rev: string | number; rev: string | number;
service: string; service: string;
style: string; style: string;
type: FskEntryTypesEnum; type: FskEntryType;
url: string; url: string;
username: string; username: string;
createdDate: number; // UNIX timestamp createdDate: number; // UNIX timestamp

View File

@@ -1,10 +1,16 @@
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents the different identity providers supported for authentication.
export enum IdpProvider { */
Azure = 0, export const IdpProvider = Object.freeze({
OktaAuthServer = 1, Azure: 0,
OktaNoAuthServer = 2, OktaAuthServer: 1,
Google = 3, OktaNoAuthServer: 2,
PingOne = 4, Google: 3,
OneLogin = 5, PingOne: 4,
} OneLogin: 5,
} as const);
/**
* Type representing valid identity provider values.
*/
export type IdpProvider = (typeof IdpProvider)[keyof typeof IdpProvider];

View File

@@ -1,7 +1,13 @@
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents LastPass login types.
export enum LastpassLoginType { */
MasterPassword = 0, export const LastpassLoginType = Object.freeze({
MasterPassword: 0,
// Not sure what Types 1 and 2 are? // Not sure what Types 1 and 2 are?
Federated = 3, Federated: 3,
} } as const);
/**
* Type representing valid LastPass login type values.
*/
export type LastpassLoginType = (typeof LastpassLoginType)[keyof typeof LastpassLoginType];

View File

@@ -1,7 +1,13 @@
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents OTP authentication methods.
export enum OtpMethod { */
GoogleAuth, export const OtpMethod = Object.freeze({
MicrosoftAuth, GoogleAuth: 0,
Yubikey, MicrosoftAuth: 1,
} Yubikey: 2,
} as const);
/**
* Type representing valid OTP method values.
*/
export type OtpMethod = (typeof OtpMethod)[keyof typeof OtpMethod];

View File

@@ -1,6 +1,12 @@
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Platform types representing different device categories.
export enum Platform { */
Desktop, export const Platform = Object.freeze({
Mobile, Desktop: 0,
} Mobile: 1,
} as const);
/**
* Type representing valid platform values.
*/
export type Platform = (typeof Platform)[keyof typeof Platform];

View File

@@ -14,12 +14,12 @@ import { BaseImporter } from "../base-importer";
import { Importer } from "../importer"; import { Importer } from "../importer";
import { import {
CategoryEnum, Category,
Details, Details,
ExportData, ExportData,
FieldsEntity, FieldsEntity,
Item, Item,
LoginFieldTypeEnum, LoginFieldType,
Overview, Overview,
PasswordHistoryEntity, PasswordHistoryEntity,
SectionsEntity, SectionsEntity,
@@ -45,38 +45,38 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
const cipher = this.initLoginCipher(); const cipher = this.initLoginCipher();
const category = item.categoryUuid as CategoryEnum; const category = item.categoryUuid as Category;
switch (category) { switch (category) {
case CategoryEnum.Login: case Category.Login:
case CategoryEnum.Database: case Category.Database:
case CategoryEnum.Password: case Category.Password:
case CategoryEnum.WirelessRouter: case Category.WirelessRouter:
case CategoryEnum.Server: case Category.Server:
case CategoryEnum.API_Credential: case Category.API_Credential:
cipher.type = CipherType.Login; cipher.type = CipherType.Login;
cipher.login = new LoginView(); cipher.login = new LoginView();
break; break;
case CategoryEnum.CreditCard: case Category.CreditCard:
case CategoryEnum.BankAccount: case Category.BankAccount:
cipher.type = CipherType.Card; cipher.type = CipherType.Card;
cipher.card = new CardView(); cipher.card = new CardView();
break; break;
case CategoryEnum.SecureNote: case Category.SecureNote:
case CategoryEnum.SoftwareLicense: case Category.SoftwareLicense:
case CategoryEnum.EmailAccount: case Category.EmailAccount:
case CategoryEnum.MedicalRecord: case Category.MedicalRecord:
// case CategoryEnum.Document: // case CategoryEnum.Document:
cipher.type = CipherType.SecureNote; cipher.type = CipherType.SecureNote;
cipher.secureNote = new SecureNoteView(); cipher.secureNote = new SecureNoteView();
cipher.secureNote.type = SecureNoteType.Generic; cipher.secureNote.type = SecureNoteType.Generic;
break; break;
case CategoryEnum.Identity: case Category.Identity:
case CategoryEnum.DriversLicense: case Category.DriversLicense:
case CategoryEnum.OutdoorLicense: case Category.OutdoorLicense:
case CategoryEnum.Membership: case Category.Membership:
case CategoryEnum.Passport: case Category.Passport:
case CategoryEnum.RewardsProgram: case Category.RewardsProgram:
case CategoryEnum.SocialSecurityNumber: case Category.SocialSecurityNumber:
cipher.type = CipherType.Identity; cipher.type = CipherType.Identity;
cipher.identity = new IdentityView(); cipher.identity = new IdentityView();
break; break;
@@ -166,10 +166,10 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
let fieldValue = loginField.value; let fieldValue = loginField.value;
let fieldType: FieldType = FieldType.Text; let fieldType: FieldType = FieldType.Text;
switch (loginField.fieldType) { switch (loginField.fieldType) {
case LoginFieldTypeEnum.Password: case LoginFieldType.Password:
fieldType = FieldType.Hidden; fieldType = FieldType.Hidden;
break; break;
case LoginFieldTypeEnum.CheckBox: case LoginFieldType.CheckBox:
fieldValue = loginField.value !== "" ? "true" : "false"; fieldValue = loginField.value !== "" ? "true" : "false";
fieldType = FieldType.Boolean; fieldType = FieldType.Boolean;
break; break;
@@ -180,8 +180,8 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
}); });
} }
private processDetails(category: CategoryEnum, details: Details, cipher: CipherView) { private processDetails(category: Category, details: Details, cipher: CipherView) {
if (category !== CategoryEnum.Password) { if (category !== Category.Password) {
return; return;
} }
@@ -191,7 +191,7 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
cipher.login.password = details.password; cipher.login.password = details.password;
} }
private processSections(category: CategoryEnum, sections: SectionsEntity[], cipher: CipherView) { private processSections(category: Category, sections: SectionsEntity[], cipher: CipherView) {
if (sections == null || sections.length === 0) { if (sections == null || sections.length === 0) {
return; return;
} }
@@ -206,7 +206,7 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
} }
private parseSectionFields( private parseSectionFields(
category: CategoryEnum, category: Category,
fields: FieldsEntity[], fields: FieldsEntity[],
cipher: CipherView, cipher: CipherView,
sectionTitle: string, sectionTitle: string,
@@ -232,20 +232,20 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
} }
switch (category) { switch (category) {
case CategoryEnum.Login: case Category.Login:
case CategoryEnum.Database: case Category.Database:
case CategoryEnum.EmailAccount: case Category.EmailAccount:
case CategoryEnum.WirelessRouter: case Category.WirelessRouter:
break; break;
case CategoryEnum.Server: case Category.Server:
if (this.isNullOrWhitespace(cipher.login.uri) && field.id === "url") { if (this.isNullOrWhitespace(cipher.login.uri) && field.id === "url") {
cipher.login.uris = this.makeUriArray(fieldValue); cipher.login.uris = this.makeUriArray(fieldValue);
return; return;
} }
break; break;
case CategoryEnum.API_Credential: case Category.API_Credential:
if (this.fillApiCredentials(field, fieldValue, cipher)) { if (this.fillApiCredentials(field, fieldValue, cipher)) {
return; return;
} }
@@ -258,7 +258,7 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
return; return;
} }
if (category === CategoryEnum.BankAccount) { if (category === Category.BankAccount) {
if (this.fillBankAccount(field, fieldValue, cipher)) { if (this.fillBankAccount(field, fieldValue, cipher)) {
return; return;
} }
@@ -281,34 +281,34 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
} }
switch (category) { switch (category) {
case CategoryEnum.Identity: case Category.Identity:
break; break;
case CategoryEnum.DriversLicense: case Category.DriversLicense:
if (this.fillDriversLicense(field, fieldValue, cipher)) { if (this.fillDriversLicense(field, fieldValue, cipher)) {
return; return;
} }
break; break;
case CategoryEnum.OutdoorLicense: case Category.OutdoorLicense:
if (this.fillOutdoorLicense(field, fieldValue, cipher)) { if (this.fillOutdoorLicense(field, fieldValue, cipher)) {
return; return;
} }
break; break;
case CategoryEnum.Membership: case Category.Membership:
if (this.fillMembership(field, fieldValue, cipher)) { if (this.fillMembership(field, fieldValue, cipher)) {
return; return;
} }
break; break;
case CategoryEnum.Passport: case Category.Passport:
if (this.fillPassport(field, fieldValue, cipher)) { if (this.fillPassport(field, fieldValue, cipher)) {
return; return;
} }
break; break;
case CategoryEnum.RewardsProgram: case Category.RewardsProgram:
if (this.fillRewardsProgram(field, fieldValue, cipher)) { if (this.fillRewardsProgram(field, fieldValue, cipher)) {
return; return;
} }
break; break;
case CategoryEnum.SocialSecurityNumber: case Category.SocialSecurityNumber:
if (this.fillSSN(field, fieldValue, cipher)) { if (this.fillSSN(field, fieldValue, cipher)) {
return; return;
} }

View File

@@ -25,30 +25,36 @@ export interface VaultAttributes {
type: string; type: string;
} }
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents the different types of items that can be stored in 1Password.
export enum CategoryEnum { */
Login = "001", export const Category = Object.freeze({
CreditCard = "002", Login: "001",
SecureNote = "003", CreditCard: "002",
Identity = "004", SecureNote: "003",
Password = "005", Identity: "004",
Document = "006", Password: "005",
SoftwareLicense = "100", Document: "006",
BankAccount = "101", SoftwareLicense: "100",
Database = "102", BankAccount: "101",
DriversLicense = "103", Database: "102",
OutdoorLicense = "104", DriversLicense: "103",
Membership = "105", OutdoorLicense: "104",
Passport = "106", Membership: "105",
RewardsProgram = "107", Passport: "106",
SocialSecurityNumber = "108", RewardsProgram: "107",
WirelessRouter = "109", SocialSecurityNumber: "108",
Server = "110", WirelessRouter: "109",
EmailAccount = "111", Server: "110",
API_Credential = "112", EmailAccount: "111",
MedicalRecord = "113", API_Credential: "112",
} MedicalRecord: "113",
} as const);
/**
* Represents valid 1Password category values.
*/
export type Category = (typeof Category)[keyof typeof Category];
export interface Item { export interface Item {
uuid: string; uuid: string;
@@ -69,23 +75,30 @@ export interface Details {
password?: string | null; password?: string | null;
} }
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Represents 1Password login field types that can be stored in login items.
export enum LoginFieldTypeEnum { */
TextOrHtml = "T", export const LoginFieldType = Object.freeze({
EmailAddress = "E", TextOrHtml: "T",
URL = "U", EmailAddress: "E",
Number = "N", URL: "U",
Password = "P", Number: "N",
TextArea = "A", Password: "P",
PhoneNumber = "TEL", TextArea: "A",
CheckBox = "C", PhoneNumber: "TEL",
} CheckBox: "C",
} as const);
/**
* Type representing valid 1Password login field type values.
*/
export type LoginFieldType = (typeof LoginFieldType)[keyof typeof LoginFieldType];
export interface LoginFieldsEntity { export interface LoginFieldsEntity {
value: string; value: string;
id: string; id: string;
name: string; name: string;
fieldType: LoginFieldTypeEnum | string; fieldType: LoginFieldType | string;
designation?: string | null; designation?: string | null;
} }
export interface SectionsEntity { export interface SectionsEntity {

View File

@@ -27,12 +27,19 @@ export type ProtonPassItem = {
pinned: boolean; pinned: boolean;
}; };
// FIXME: update to use a const object instead of a typescript enum /**
// eslint-disable-next-line @bitwarden/platform/no-enums * Proton Pass item states as a const object.
export enum ProtonPassItemState { * Represents the different states an item can be in (active or trashed).
ACTIVE = 1, */
TRASHED = 2, export const ProtonPassItemState = Object.freeze({
} ACTIVE: 1,
TRASHED: 2,
} as const);
/**
* Type representing valid Proton Pass item state values.
*/
export type ProtonPassItemState = (typeof ProtonPassItemState)[keyof typeof ProtonPassItemState];
export type ProtonPassItemData = { export type ProtonPassItemData = {
metadata: ProtonPassItemMetadata; metadata: ProtonPassItemMetadata;