Skip to content

Commit cdecb05

Browse files
committed
replace Autofill-owned enums
1 parent 79fa246 commit cdecb05

23 files changed

+111
-109
lines changed

apps/browser/src/autofill/background/abstractions/overlay.background.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CipherType } from "@bitwarden/common/vault/enums";
44
import { CipherRepromptType } from "@bitwarden/common/vault/enums/cipher-reprompt-type";
55
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
66

7-
import { InlineMenuFillTypes } from "../../enums/autofill-overlay.enum";
7+
import { InlineMenuFillType } from "../../enums/autofill-overlay.enum";
88
import AutofillPageDetails from "../../models/autofill-page-details";
99
import { PageDetail } from "../../services/abstractions/autofill.service";
1010

@@ -43,7 +43,7 @@ export type UpdateOverlayCiphersParams = {
4343
export type FocusedFieldData = {
4444
focusedFieldStyles: Partial<CSSStyleDeclaration>;
4545
focusedFieldRects: Partial<DOMRect>;
46-
inlineMenuFillType?: InlineMenuFillTypes;
46+
inlineMenuFillType?: InlineMenuFillType;
4747
tabId?: number;
4848
frameId?: number;
4949
accountCreationFieldType?: string;

apps/browser/src/autofill/background/overlay.background.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
797797
* @param focusedFieldData - Optional focused field data to validate against
798798
*/
799799
private focusedFieldMatchesFillType(
800-
fillType: InlineMenuFillTypes,
800+
fillType: InlineMenuFillType,
801801
focusedFieldData?: FocusedFieldData,
802802
) {
803803
const focusedFieldFillType = focusedFieldData
@@ -806,7 +806,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
806806

807807
// When updating the current password for a field, it should fill with a login cipher
808808
if (
809-
focusedFieldFillType === InlineMenuFillType.CurrentPasswordUpdate &&
809+
focusedFieldFillType === InlineMenuFillTypes.CurrentPasswordUpdate &&
810810
fillType === CipherType.Login
811811
) {
812812
return true;
@@ -819,7 +819,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
819819
* Identifies whether the inline menu is being shown on an account creation field.
820820
*/
821821
private shouldShowInlineMenuAccountCreation(): boolean {
822-
if (this.focusedFieldMatchesFillType(InlineMenuFillType.AccountCreationUsername)) {
822+
if (this.focusedFieldMatchesFillType(InlineMenuFillTypes.AccountCreationUsername)) {
823823
return true;
824824
}
825825

@@ -1152,7 +1152,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
11521152
}
11531153

11541154
let pageDetails = Array.from(pageDetailsForTab.values());
1155-
if (this.focusedFieldMatchesFillType(InlineMenuFillType.CurrentPasswordUpdate)) {
1155+
if (this.focusedFieldMatchesFillType(InlineMenuFillTypes.CurrentPasswordUpdate)) {
11561156
pageDetails = this.getFilteredPageDetails(
11571157
pageDetails,
11581158
this.inlineMenuFieldQualificationService.isUpdateCurrentPasswordField,
@@ -1705,7 +1705,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
17051705
private shouldUpdatePasswordGeneratorMenuOnFieldFocus() {
17061706
return (
17071707
this.isInlineMenuButtonVisible &&
1708-
this.focusedFieldMatchesFillType(InlineMenuFillType.PasswordGeneration)
1708+
this.focusedFieldMatchesFillType(InlineMenuFillTypes.PasswordGeneration)
17091709
);
17101710
}
17111711

@@ -1767,9 +1767,9 @@ export class OverlayBackground implements OverlayBackgroundInterface {
17671767
private shouldUpdateAccountCreationMenuOnFieldFocus(previousFocusedFieldData: FocusedFieldData) {
17681768
const accountCreationFieldBlurred =
17691769
this.focusedFieldMatchesFillType(
1770-
InlineMenuFillType.AccountCreationUsername,
1770+
InlineMenuFillTypes.AccountCreationUsername,
17711771
previousFocusedFieldData,
1772-
) && !this.focusedFieldMatchesFillType(InlineMenuFillType.AccountCreationUsername);
1772+
) && !this.focusedFieldMatchesFillType(InlineMenuFillTypes.AccountCreationUsername);
17731773
return accountCreationFieldBlurred || this.shouldShowInlineMenuAccountCreation();
17741774
}
17751775

@@ -1876,7 +1876,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
18761876

18771877
return (
18781878
(this.shouldShowInlineMenuAccountCreation() ||
1879-
this.focusedFieldMatchesFillType(InlineMenuFillType.PasswordGeneration)) &&
1879+
this.focusedFieldMatchesFillType(InlineMenuFillTypes.PasswordGeneration)) &&
18801880
!!(loginData.password || loginData.newPassword)
18811881
);
18821882
}
@@ -3036,7 +3036,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
30363036
}
30373037

30383038
const focusFieldShouldShowPasswordGenerator =
3039-
this.focusedFieldMatchesFillType(InlineMenuFillType.PasswordGeneration) ||
3039+
this.focusedFieldMatchesFillType(InlineMenuFillTypes.PasswordGeneration) ||
30403040
(showInlineMenuAccountCreation &&
30413041
this.focusedFieldMatchesAccountCreationType(InlineMenuAccountCreationFieldType.Password));
30423042
if (!focusFieldShouldShowPasswordGenerator) {

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/action-button.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ It is designed with accessibility and responsive design in mind.
2020
| `buttonAction` | `(e: Event) => void` | Yes | The function to execute when the button is clicked. |
2121
| `buttonText` | `string` | Yes | The text to display on the button. |
2222
| `disabled` | `boolean` (default: false) | No | Disables the button when set to `true`. |
23-
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` enum. |
23+
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` type. |
2424

2525
## Installation and Setup
2626

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/badge-button.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ handling, and a disabled state. The component is optimized for accessibility and
2020
| `buttonAction` | `(e: Event) => void` | Yes | The function to execute when the button is clicked. |
2121
| `buttonText` | `string` | Yes | The text to display on the badge button. |
2222
| `disabled` | `boolean` (default: false) | No | Disables the button when set to `true`. |
23-
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` enum. |
23+
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` type. |
2424

2525
## Installation and Setup
2626

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/body.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ presenting actionable information.
1919
| ------------------ | ------------------ | ------------ | --------------------------------------------------------------------------------------------------------- |
2020
| `ciphers` | `CipherData[]` | Yes | An array of cipher data objects. Each cipher includes metadata such as ID, name, type, and login details. |
2121
| `notificationType` | `NotificationType` | Yes | Specifies the type of notification, such as `add`, `change`, `unlock`, or `fileless-import`. |
22-
| `theme` | `Theme` | Yes | Defines the theme used for styling the notification. Must match the `Theme` enum. |
22+
| `theme` | `Theme` | Yes | Defines the theme used for styling the notification. Must match the `Theme` type. |
2323

2424
---
2525

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/close-button.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ a close icon for visual clarity. The component is designed to be intuitive and a
1717
| **Prop** | **Type** | **Required** | **Description** |
1818
| ------------------------- | -------------------- | ------------ | ----------------------------------------------------------- |
1919
| `handleCloseNotification` | `(e: Event) => void` | Yes | The function to execute when the button is clicked. |
20-
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` enum. |
20+
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` type. |
2121

2222
## Installation and Setup
2323

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/edit-button.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ or settings where inline editing is required.
2020
| `buttonAction` | `(e: Event) => void` | Yes | The function to execute when the button is clicked. |
2121
| `buttonText` | `string` | Yes | The text displayed as the button's tooltip. |
2222
| `disabled` | `boolean` (default: false) | No | Disables the button when set to `true`. |
23-
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` enum. |
23+
| `theme` | `Theme` | Yes | The theme to style the button. Must match the `Theme` type. |
2424

2525
## Installation and Setup
2626

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/footer.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ customization based on the `theme` and `notificationType`.
1717
| **Prop** | **Type** | **Required** | **Description** |
1818
| ------------------ | ------------------ | ------------ | -------------------------------------------------------------------------------------------------- |
1919
| `notificationType` | `NotificationType` | Yes | The type of notification footer to display. Options: `add`, `change`, `unlock`, `fileless-import`. |
20-
| `theme` | `Theme` | Yes | Defines the theme of the notification footer. Must match the `Theme` enum. |
20+
| `theme` | `Theme` | Yes | Defines the theme of the notification footer. Must match the `Theme` type. |
2121

2222
---
2323

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/header.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ and an optional close button. This component is versatile and can be styled dyna
1919
| ------------------------- | -------------------- | ------------ | ------------------------------------------------------------------- |
2020
| `message` | `string` | Yes | The text message to be displayed in the notification. |
2121
| `standalone` | `boolean` | No | Determines if the notification is displayed independently. |
22-
| `theme` | `Theme` | Yes | Defines the theme of the notification. Must match the `Theme` enum. |
22+
| `theme` | `Theme` | Yes | Defines the theme of the notification. Must match the `Theme` type. |
2323
| `handleCloseNotification` | `(e: Event) => void` | No | A callback function triggered when the close button is clicked. |
2424

2525
---

apps/browser/src/autofill/content/components/lit-stories/.lit-docs/icons.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ like size, color, and theme. Each story is an example of how a specific icon can
2828
| `iconLink` | `URL` | No | Defines an external URL associated with the icon, prop exclusive to `Brand Icon`. |
2929
| `color` | `string` | No | Sets the color of the icon. |
3030
| `disabled` | `boolean` | No | Disables the icon visually and functionally. |
31-
| `theme` | `Theme` | Yes | Defines the theme used to style the icons. Must match the `Theme` enum. |
31+
| `theme` | `Theme` | Yes | Defines the theme used to style the icons. Must match the `Theme` type. |
3232
| `size` | `number` | Yes | Sets the width and height of the icon in pixels. |
3333

3434
---

apps/browser/src/autofill/enums/autofill-overlay.enum.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ export const RedirectFocusDirection = {
2121
Next: "next",
2222
} as const;
2323

24-
// FIXME: update to use a const object instead of a typescript enum
25-
// eslint-disable-next-line @bitwarden/platform/no-enums
26-
export enum InlineMenuFillType {
27-
AccountCreationUsername = 5,
28-
PasswordGeneration = 6,
29-
CurrentPasswordUpdate = 7,
30-
}
31-
export type InlineMenuFillTypes = InlineMenuFillType | CipherType;
24+
export const InlineMenuFillTypes = {
25+
AccountCreationUsername: 5,
26+
PasswordGeneration: 6,
27+
CurrentPasswordUpdate: 7,
28+
} as const;
29+
30+
export type InlineMenuFillTypeValue =
31+
(typeof InlineMenuFillTypes)[keyof typeof InlineMenuFillTypes];
32+
33+
export type InlineMenuFillType = InlineMenuFillTypeValue | CipherType;
3234

3335
export const InlineMenuAccountCreationFieldType = {
3436
Text: "text",

apps/browser/src/autofill/fido2/content/fido2-content-script.spec.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createPortSpyMock } from "../../../autofill/spec/autofill-mocks";
66
import { triggerPortOnDisconnectEvent } from "../../../autofill/spec/testing-utils";
77
import { Fido2PortName } from "../enums/fido2-port-name.enum";
88

9-
import { InsecureCreateCredentialParams, MessageType } from "./messaging/message";
9+
import { InsecureCreateCredentialParams, MessageTypes } from "./messaging/message";
1010
import { MessageWithMetadata, Messenger } from "./messaging/messenger";
1111

1212
jest.mock("../../../autofill/utils", () => ({
@@ -71,7 +71,7 @@ describe("Fido2 Content Script", () => {
7171

7272
it("handles a FIDO2 credential creation request message from the window message listener, formats the message and sends the formatted message to the extension background", async () => {
7373
const message = mock<MessageWithMetadata>({
74-
type: MessageType.CredentialCreationRequest,
74+
type: MessageTypes.CredentialCreationRequest,
7575
data: mock<InsecureCreateCredentialParams>(),
7676
});
7777
const mockResult = { credentialId: "mock" } as CreateCredentialResult;
@@ -92,14 +92,14 @@ describe("Fido2 Content Script", () => {
9292
requestId: expect.any(String),
9393
});
9494
expect(response).toEqual({
95-
type: MessageType.CredentialCreationResponse,
95+
type: MessageTypes.CredentialCreationResponse,
9696
result: mockResult,
9797
});
9898
});
9999

100100
it("handles a FIDO2 credential get request message from the window message listener, formats the message and sends the formatted message to the extension background", async () => {
101101
const message = mock<MessageWithMetadata>({
102-
type: MessageType.CredentialGetRequest,
102+
type: MessageTypes.CredentialGetRequest,
103103
data: mock<InsecureCreateCredentialParams>(),
104104
});
105105

@@ -121,7 +121,7 @@ describe("Fido2 Content Script", () => {
121121

122122
it("removes the abort handler when the FIDO2 request is complete", async () => {
123123
const message = mock<MessageWithMetadata>({
124-
type: MessageType.CredentialCreationRequest,
124+
type: MessageTypes.CredentialCreationRequest,
125125
data: mock<InsecureCreateCredentialParams>(),
126126
});
127127
const abortController = new AbortController();
@@ -138,16 +138,14 @@ describe("Fido2 Content Script", () => {
138138

139139
it("sends an extension message to abort the FIDO2 request when the abort controller is signaled", async () => {
140140
const message = mock<MessageWithMetadata>({
141-
type: MessageType.CredentialCreationRequest,
141+
type: MessageTypes.CredentialCreationRequest,
142142
data: mock<InsecureCreateCredentialParams>(),
143143
});
144144
const abortController = new AbortController();
145145
const abortSpy = jest.spyOn(abortController.signal, "addEventListener");
146-
jest
147-
.spyOn(chrome.runtime, "sendMessage")
148-
.mockImplementationOnce(async (extensionId: string, message: unknown, options: any) => {
149-
abortController.abort();
150-
});
146+
jest.spyOn(chrome.runtime, "sendMessage").mockImplementationOnce(async () => {
147+
abortController.abort();
148+
});
151149

152150
// FIXME: Remove when updating file. Eslint update
153151
// eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -165,7 +163,7 @@ describe("Fido2 Content Script", () => {
165163
it("rejects credential requests and returns an error result", async () => {
166164
const errorMessage = "Test error";
167165
const message = mock<MessageWithMetadata>({
168-
type: MessageType.CredentialCreationRequest,
166+
type: MessageTypes.CredentialCreationRequest,
169167
data: mock<InsecureCreateCredentialParams>(),
170168
});
171169
const abortController = new AbortController();

apps/browser/src/autofill/fido2/content/fido2-content-script.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
InsecureAssertCredentialParams,
1313
InsecureCreateCredentialParams,
1414
Message,
15-
MessageType,
15+
MessageTypes,
1616
} from "./messaging/message";
1717
import { MessageWithMetadata, Messenger } from "./messaging/messenger";
1818

@@ -49,21 +49,21 @@ import { MessageWithMetadata, Messenger } from "./messaging/messenger";
4949
abortController.signal.addEventListener("abort", abortHandler);
5050

5151
try {
52-
if (message.type === MessageType.CredentialCreationRequest) {
52+
if (message.type === MessageTypes.CredentialCreationRequest) {
5353
return handleCredentialCreationRequestMessage(
5454
requestId,
5555
message.data as InsecureCreateCredentialParams,
5656
);
5757
}
5858

59-
if (message.type === MessageType.CredentialGetRequest) {
59+
if (message.type === MessageTypes.CredentialGetRequest) {
6060
return handleCredentialGetRequestMessage(
6161
requestId,
6262
message.data as InsecureAssertCredentialParams,
6363
);
6464
}
6565

66-
if (message.type === MessageType.AbortRequest) {
66+
if (message.type === MessageTypes.AbortRequest) {
6767
return sendExtensionMessage("fido2AbortRequest", { abortedRequestId: requestId });
6868
}
6969
} finally {
@@ -83,7 +83,7 @@ import { MessageWithMetadata, Messenger } from "./messaging/messenger";
8383
): Promise<Message | undefined> {
8484
return respondToCredentialRequest(
8585
"fido2RegisterCredentialRequest",
86-
MessageType.CredentialCreationResponse,
86+
MessageTypes.CredentialCreationResponse,
8787
requestId,
8888
data,
8989
);
@@ -101,7 +101,7 @@ import { MessageWithMetadata, Messenger } from "./messaging/messenger";
101101
): Promise<Message | undefined> {
102102
return respondToCredentialRequest(
103103
"fido2GetCredentialRequest",
104-
MessageType.CredentialGetResponse,
104+
MessageTypes.CredentialGetResponse,
105105
requestId,
106106
data,
107107
);
@@ -118,7 +118,9 @@ import { MessageWithMetadata, Messenger } from "./messaging/messenger";
118118
*/
119119
async function respondToCredentialRequest(
120120
command: string,
121-
type: MessageType.CredentialCreationResponse | MessageType.CredentialGetResponse,
121+
type:
122+
| typeof MessageTypes.CredentialCreationResponse
123+
| typeof MessageTypes.CredentialGetResponse,
122124
requestId: string,
123125
messageData: InsecureCreateCredentialParams | InsecureAssertCredentialParams,
124126
): Promise<Message | undefined> {

0 commit comments

Comments
 (0)