Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6937282
initial refactor to avoid deprecated getOrgKey() method
harr1424 Sep 8, 2025
a1b316f
added mocks necessary for testing updated KeyService methods
harr1424 Sep 8, 2025
4e68f24
added error handling to match file specific conventions
harr1424 Sep 9, 2025
6828f69
Merge branch 'PM-24099-Tools-Remove-getOrgKey-from-the-key-service' iโ€ฆ
harr1424 Sep 9, 2025
bb89cd9
initial refactor isolated to send.ts and platform services container
harr1424 Sep 9, 2025
8fff591
functional and unit tests pass after adding AccountService to global โ€ฆ
harr1424 Sep 9, 2025
0e94644
modified send.ts to use correct EncKey with test coverage
harr1424 Sep 9, 2025
30fd988
Refactor complete with passing unit tests
harr1424 Sep 9, 2025
dae7d41
PM-24105 refactoring complete with updated test coverage
harr1424 Sep 10, 2025
949f6a5
prefer using class members and testing with real GUIDs
harr1424 Sep 10, 2025
adbbf6a
prefer local userId when available & guard against null
harr1424 Sep 10, 2025
83c2b92
fix build errors
harr1424 Sep 10, 2025
a2e1081
Fix runtime errors and send regression
harr1424 Sep 10, 2025
948c6e3
PM-24099 refactor UserId collection from AccountService to wait for nโ€ฆ
harr1424 Sep 11, 2025
9ef9c32
PM-24106 fix breaking changes to send on desktop and CLI
harr1424 Sep 11, 2025
970bc9f
PM-24105 revert removal of Promise and .vscode setting
harr1424 Sep 11, 2025
38dbe74
PM-22143 initial commit to check lints
harr1424 Sep 11, 2025
196dcbe
PM-22143 WIP progress checkpoint
harr1424 Sep 11, 2025
19f5e10
PM-22143 replace all tools-owned enums with const objects
harr1424 Sep 12, 2025
0577917
PM-22143 fix build errors in browser and cli
harr1424 Sep 12, 2025
e1875a9
revert vs code settings to match origin
harr1424 Sep 12, 2025
0517e28
revert auto-generated desktop_native file
harr1424 Sep 15, 2025
19d4a02
resolve actions requested during review
harr1424 Sep 15, 2025
356ffb1
update types for enhanced runtime safety
harr1424 Sep 15, 2025
a911b08
address issues found during review
harr1424 Sep 16, 2025
30b430a
address remaining review items
harr1424 Sep 17, 2025
9b8b8aa
address review items
harr1424 Sep 17, 2025
c0255ba
Merge remote-tracking branch 'origin/main' into PM-22143-Tools-Refactโ€ฆ
harr1424 Sep 22, 2025
2314d44
Merge remote-tracking branch 'origin/main' into PM-24099-Tools-Removeโ€ฆ
harr1424 Sep 22, 2025
542e2c3
use UserId value made available in PM-24146
harr1424 Sep 22, 2025
b34f4ea
address review items
harr1424 Sep 25, 2025
4f2461d
remove org export key fallback to user key
harr1424 Sep 25, 2025
6e30700
Merge remote-tracking branch 'origin/PM-24099-Tools-Remove-getOrgKey-โ€ฆ
harr1424 Sep 28, 2025
8265b7c
use existing getUserId utility method
harr1424 Sep 29, 2025
8641595
prefer const vs type casting & remove unused helper method
harr1424 Sep 29, 2025
380fad1
add null check to fix strict type error
harr1424 Sep 29, 2025
b1b5f2f
partially address review items:
harr1424 Oct 2, 2025
8614dcf
lift UserId retrieval to occur once during import
harr1424 Oct 3, 2025
4da1fa1
Merge branch 'main' into PM-24105-Tools-Remove-getUserKey-on-the-key-โ€ฆ
harr1424 Oct 3, 2025
6d58a91
Merge branch 'main' into PM-24105-Tools-Remove-getUserKey-on-the-key-โ€ฆ
harr1424 Oct 3, 2025
a4e4a70
remove unused import not caught during commit workflow
harr1424 Oct 3, 2025
c97b17a
Merge branch 'PM-24105-Tools-Remove-getUserKey-on-the-key-service' ofโ€ฆ
harr1424 Oct 3, 2025
687ca14
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Oct 6, 2025
1d52c7a
isolate import related changes
harr1424 Oct 7, 2025
624109e
respond to review items
harr1424 Oct 8, 2025
e6c16b7
add export related code changes
harr1424 Oct 8, 2025
7fc47f2
remove redundnat userId retrieval
harr1424 Oct 8, 2025
a78c779
Merge branch 'PM-22143-import-only-enum-refactor' into PM-22143-Toolsโ€ฆ
harr1424 Oct 8, 2025
63c3049
Merge branch 'PM-24105-Tools-Remove-getUserKey-on-the-key-service' inโ€ฆ
harr1424 Oct 8, 2025
5884b00
Merge branch 'PM-22143-Tools-Refactor-TS-Enums-to-be-const-objects-EXโ€ฆ
harr1424 Oct 8, 2025
95f07c6
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Oct 15, 2025
af4da3e
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Nov 20, 2025
2993d93
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Nov 20, 2025
ee785f2
respond to review comments
harr1424 Nov 20, 2025
57a7ba6
respond to review comment (remove unused helpers)
harr1424 Nov 20, 2025
992f11f
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Nov 20, 2025
4345d72
Merge branch 'main' into PM-22143-Tools-Refactor-TS-Enums-to-be-constโ€ฆ
harr1424 Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { SendFilePopoutDialogContainerComponent } from "../send-file-popout-dial
class QueryParams {
constructor(params: Params) {
this.sendId = params.sendId;
this.type = parseInt(params.type, 10);
this.type = parseInt(params.type, 10) as SendType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { PopupHeaderComponent } from "../../../platform/popup/layout/popup-heade
import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.component";
import { PopupRouterCacheService } from "../../../platform/popup/view-cache/popup-router-cache.service";

import { SendV2Component, SendState } from "./send-v2.component";
import { SendV2Component } from "./send-v2.component";

describe("SendV2Component", () => {
let component: SendV2Component;
Expand Down Expand Up @@ -142,12 +142,12 @@ describe("SendV2Component", () => {
it("should set listState to Empty when emptyList$ emits true", () => {
sendItemsServiceEmptyList$.next(true);
fixture.detectChanges();
expect(component["listState"]).toBe(SendState.Empty);
expect(component["listState"]).toBe(component["sendState"].Empty);
Copy link
Member

@Hinton Hinton Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why are we modifying this? The SendState type is public so we should be able to continue using it?

});

it("should set listState to NoResults when noFilteredResults$ emits true", () => {
sendItemsServiceNoFilteredResults$.next(true);
fixture.detectChanges();
expect(component["listState"]).toBe(SendState.NoResults);
expect(component["listState"]).toBe(component["sendState"].NoResults);
Copy link
Member

@Hinton Hinton Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Why are we modifying this? The SendState type is public so we should be able to continue using it?

});
});
14 changes: 7 additions & 7 deletions apps/browser/src/tools/popup/send-v2/send-v2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import { PopOutComponent } from "../../../platform/popup/components/pop-out.comp
import { PopupHeaderComponent } from "../../../platform/popup/layout/popup-header.component";
import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.component";

// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum SendState {
Empty,
NoResults,
}
export const SendState = Object.freeze({
Empty: "Empty",
NoResults: "NoResults",
} as const);

export type SendState = (typeof SendState)[keyof typeof SendState];

@Component({
templateUrl: "send-v2.component.html",
Expand Down Expand Up @@ -83,7 +83,7 @@ export class SendV2Component implements OnDestroy {
.pipe(takeUntilDestroyed())
.subscribe(([emptyList, noFilteredResults, currentFilter]) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to add types for the args

if (currentFilter?.sendType !== null) {
this.title = `${this.sendType[currentFilter.sendType].toLowerCase()}Sends`;
this.title = `${currentFilter.sendType === SendType.File ? "file" : "text"}Sends`;
} else {
this.title = "allSends";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be this to avoid nested if conditions

if (currentFilter?.sendType != null) {
const titleMap: Record<SendType, string> = {
[SendType.File]: 'fileSends',
[SendType.Text]: 'textSends'
};

this.title = titleMap[currentFilter.sendType] ?? 'allSends';
} else {
this.title = 'allSends';
}

Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/tools/send/send.program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class SendProgram extends BaseProgram {
let sendFile = null;
let sendText = null;
let name = Utils.newGuid();
let type = SendType.Text;
let type: SendType = SendType.Text;
if (options.file != null) {
data = path.resolve(data);
if (!fs.existsSync(data)) {
Expand All @@ -316,7 +316,7 @@ export class SendProgram extends BaseProgram {

sendFile = SendFileResponse.template(data);
name = path.basename(data);
type = SendType.File;
type = SendType.File as SendType;
} else {
sendText = SendTextResponse.template(data, options.hidden);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/desktop_native/napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ export declare namespace chromium_importer {
login?: Login
failure?: LoginImportFailure
}
export function getInstalledBrowsers(): Promise<Array<string>>
export function getAvailableProfiles(browser: string): Promise<Array<ProfileInfo>>
export function getInstalledBrowsers(): Array<string>
export function getAvailableProfiles(browser: string): Array<ProfileInfo>
export function importLogins(browser: string, profileId: string): Promise<Array<LoginImportResult>>
}
export declare namespace autotype {
Expand Down
14 changes: 7 additions & 7 deletions apps/desktop/src/app/tools/send/send.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import { SearchBarService } from "../../layout/search/search-bar.service";

import { AddEditComponent } from "./add-edit.component";

// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
enum Action {
None = "",
Add = "add",
Edit = "edit",
}
export const Action = Object.freeze({
None: "",
Add: "add",
Edit: "edit",
} as const);

export type Action = (typeof Action)[keyof typeof Action];

const BroadcasterSubscriptionId = "SendComponent";

Expand Down
27 changes: 13 additions & 14 deletions libs/angular/src/tools/send/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.s
import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction";
import { DialogService, ToastService } from "@bitwarden/components";

// Value = hours
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
enum DatePreset {
OneHour = 1,
OneDay = 24,
TwoDays = 48,
ThreeDays = 72,
SevenDays = 168,
ThirtyDays = 720,
Custom = 0,
Never = null,
}
export const DatePreset = Object.freeze({
OneHour: 1,
OneDay: 24,
TwoDays: 48,
ThreeDays: 72,
SevenDays: 168,
ThirtyDays: 720,
Custom: 0,
Never: -1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โ“ The value of Never changed. What implications are there on the rest of the file?

๐Ÿค” Consider using DatePreset | unknown to represent the "never" case.

โ›๏ธ Please document exported members.

Copy link
Contributor Author

@harr1424 harr1424 Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are OK with it, I would like to continue with the value -1 as it seems more specific/concrete. After I made the change, I reviewed the file, and all of the comparisons appear to function as before. One spot I was concerned about:

  expirationDatePresets: DatePresetSelectOption[] = [
    { name: this.i18nService.t("never"), value: DatePreset.Never },
    ...this.deletionDatePresets,
  ];

This actually doesn't result in -1 being presented in the UI because the value is only used internally, the name is what is shown in the drop down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โŒ The values of this enum are expressed in hours. -1 is never a valid hour value, and it could produce undefined behavior in consuming logic.

๐ŸŽจ You can create a concrete value using structural typing:

const f : DatePreset | "never";

And then create narrowing utilities as described in our contrib docs to determine when you're working with a valid DatePreset. This has the added benefit of being able to verify that invalid values in between the existing values (e.g. 5) do not result in seemingly-valid inputs.

} as const);

export type DatePreset = (typeof DatePreset)[keyof typeof DatePreset];

interface DatePresetSelectOption {
name: string;
Expand Down Expand Up @@ -114,7 +113,7 @@ export class AddEditComponent implements OnInit, OnDestroy {
type: [],
defaultExpirationDateTime: [],
defaultDeletionDateTime: ["", Validators.required],
selectedDeletionDatePreset: [DatePreset.SevenDays, Validators.required],
selectedDeletionDatePreset: [DatePreset.SevenDays as DatePreset, Validators.required],
selectedExpirationDatePreset: [],
});

Expand Down
12 changes: 6 additions & 6 deletions libs/common/src/tools/send/enums/send-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum SendType {
Text = 0,
File = 1,
}
export const SendType = Object.freeze({
Text: 0,
File: 1,
} as const);

export type SendType = (typeof SendType)[keyof typeof SendType];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum EncryptedExportType {
AccountEncrypted = 0,
FileEncrypted = 1,
}
export const EncryptedExportType = Object.freeze({
AccountEncrypted: 0,
FileEncrypted: 1,
} as const);

export type EncryptedExportType = (typeof EncryptedExportType)[keyof typeof EncryptedExportType];
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,12 @@ export interface SendItemDialogParams {
disableForm?: boolean;
}

// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum SendItemDialogResult {
/**
* A Send was saved (created or updated).
*/
Saved = "saved",
export const SendItemDialogResult = Object.freeze({
Saved: "saved",
Deleted: "deleted",
} as const);

/**
* A Send was deleted.
*/
Deleted = "deleted",
}
export type SendItemDialogResult = (typeof SendItemDialogResult)[keyof typeof SendItemDialogResult];

/**
* Component for adding or editing a send item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ import { SendOptionsComponent } from "../options/send-options.component";
import { SendFileDetailsComponent } from "./send-file-details.component";
import { SendTextDetailsComponent } from "./send-text-details.component";

// Value = hours
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum DatePreset {
OneHour = 1,
OneDay = 24,
TwoDays = 48,
ThreeDays = 72,
SevenDays = 168,
FourteenDays = 336,
ThirtyDays = 720,
}
export const DatePreset = Object.freeze({
OneHour: 1,
OneDay: 24,
TwoDays: 48,
ThreeDays: 72,
SevenDays: 168,
FourteenDays: 336,
ThirtyDays: 720,
} as const);

export type DatePreset = (typeof DatePreset)[keyof typeof DatePreset];

export interface DatePresetSelectOption {
name: string;
Expand Down
Loading