1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +00:00

[SG 623] Send Service Refactor (#4327)

* Split out api methods into sendApiService

* Move SendService and abstraction

* Libs updates

* Web updates

* CLI updates

* Desktop updates

* libs send service fixes

* browser factory additions

* Browser updates

* Fix service injection for CLI SendReceiveCommand

* Deprecate directly calling send state service methods

* SendService observables updates

* Update components to use new observables

* Modify CLI to use state service instead of observables

* Remove unnecessary await on get()

* Move delete() to InternalSendService

* SendService unit tests

* Split fileUploadService by send and cipher

* send and cipher service factory updates

* Add file upload methods to get around circular dependency issues

* Move api methods from sendService to sendApiService

* Update cipherService to use fileApi methods

* libs service injection and component changes

* browser service injection and component changes

* Desktop component changes

* Web component changes

* cipher service test fix

* Fix file capitalization

* CLI service import and command updates

* Remove extra abstract fileUploadService

* WIP: Condense callbacks for file upload

Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com>

* Send callbacks for file upload

* Fix circular service dependencies

* Fix response return on upload

* Fix function definitions

* Service injection fixes and bug fixes

* Fix folder casing

* Service injection cleanup

* Remove deleted file from capital letters whitelist

* Create new SendApiService for popup

* Move cipherFileUploadService to vault

* Move SendFileUploadService methods into SendApiService

* Rename methods to remove 'WithServer'

* Properly subscribe to sendViews

* Fix Send serialization

* Implement fromJSON on sendFile and sendText

* [PM-1347] Fix send key serialization (#4989)

* Properly serialize key on send fromJSON

* Remove call that nulled out decrypted sends

* Fix null checks in fromJSON methods for models

* lint fixes

---------

Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
This commit is contained in:
Robyn MacCallum
2023-03-28 12:37:40 -04:00
committed by GitHub
parent c2bfb2497b
commit d799529428
58 changed files with 1333 additions and 663 deletions

View File

@@ -2,7 +2,8 @@ import * as fs from "fs";
import * as path from "path";
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendApiService } from "@bitwarden/common/abstractions/send/send-api.service.abstraction";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SendType } from "@bitwarden/common/enums/sendType";
import { NodeUtils } from "@bitwarden/common/misc/nodeUtils";
@@ -16,7 +17,8 @@ export class SendCreateCommand {
constructor(
private sendService: SendService,
private stateService: StateService,
private environmentService: EnvironmentService
private environmentService: EnvironmentService,
private sendApiService: SendApiService
) {}
async run(requestJson: any, cmdOptions: Record<string, any>) {
@@ -120,8 +122,8 @@ export class SendCreateCommand {
encSend.deletionDate = sendView.deletionDate;
encSend.expirationDate = sendView.expirationDate;
await this.sendService.saveWithServer([encSend, fileData]);
const newSend = await this.sendService.get(encSend.id);
await this.sendApiService.save([encSend, fileData]);
const newSend = await this.sendService.getFromState(encSend.id);
const decSend = await newSend.decrypt();
const res = new SendResponse(decSend, this.environmentService.getWebVaultUrl());
return Response.success(res);

View File

@@ -1,19 +1,20 @@
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendApiService } from "@bitwarden/common/abstractions/send/send-api.service.abstraction";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { Response } from "../../models/response";
export class SendDeleteCommand {
constructor(private sendService: SendService) {}
constructor(private sendService: SendService, private sendApiService: SendApiService) {}
async run(id: string) {
const send = await this.sendService.get(id);
const send = await this.sendService.getFromState(id);
if (send == null) {
return Response.notFound();
}
try {
await this.sendService.deleteWithServer(id);
await this.sendApiService.delete(id);
return Response.success();
} catch (e) {
return Response.error(e);

View File

@@ -1,4 +1,5 @@
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendApiService } from "@bitwarden/common/abstractions/send/send-api.service.abstraction";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SendType } from "@bitwarden/common/enums/sendType";
@@ -12,7 +13,8 @@ export class SendEditCommand {
constructor(
private sendService: SendService,
private stateService: StateService,
private getCommand: SendGetCommand
private getCommand: SendGetCommand,
private sendApiService: SendApiService
) {}
async run(requestJson: string, cmdOptions: Record<string, any>): Promise<Response> {
@@ -45,7 +47,7 @@ export class SendEditCommand {
req.id = req.id.toLowerCase();
}
const send = await this.sendService.get(req.id);
const send = await this.sendService.getFromState(req.id);
if (send == null) {
return Response.notFound();
@@ -72,7 +74,7 @@ export class SendEditCommand {
encSend.deletionDate = sendView.deletionDate;
encSend.expirationDate = sendView.expirationDate;
await this.sendService.saveWithServer([encSend, encFileData]);
await this.sendApiService.save([encSend, encFileData]);
} catch (e) {
return Response.error(e);
}

View File

@@ -3,7 +3,7 @@ import * as program from "commander";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { Utils } from "@bitwarden/common/misc/utils";
import { SendView } from "@bitwarden/common/models/view/send.view";
@@ -66,12 +66,12 @@ export class SendGetCommand extends DownloadCommand {
private async getSendView(id: string): Promise<SendView | SendView[]> {
if (Utils.isGuid(id)) {
const send = await this.sendService.get(id);
const send = await this.sendService.getFromState(id);
if (send != null) {
return await send.decrypt();
}
} else if (id.trim() !== "") {
let sends = await this.sendService.getAllDecrypted();
let sends = await this.sendService.getAllDecryptedFromState();
sends = this.searchService.searchSends(sends, id);
if (sends.length > 1) {
return sends;

View File

@@ -1,6 +1,6 @@
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { Response } from "../../models/response";
import { ListResponse } from "../../models/response/list.response";
@@ -14,7 +14,7 @@ export class SendListCommand {
) {}
async run(cmdOptions: Record<string, any>): Promise<Response> {
let sends = await this.sendService.getAllDecrypted();
let sends = await this.sendService.getAllDecryptedFromState();
const normalizedOptions = new Options(cmdOptions);
if (normalizedOptions.search != null && normalizedOptions.search.trim() !== "") {

View File

@@ -6,6 +6,7 @@ import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { CryptoFunctionService } from "@bitwarden/common/abstractions/cryptoFunction.service";
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { SendApiService } from "@bitwarden/common/abstractions/send/send-api.service.abstraction";
import { SendType } from "@bitwarden/common/enums/sendType";
import { NodeUtils } from "@bitwarden/common/misc/nodeUtils";
import { Utils } from "@bitwarden/common/misc/utils";
@@ -29,7 +30,8 @@ export class SendReceiveCommand extends DownloadCommand {
cryptoService: CryptoService,
private cryptoFunctionService: CryptoFunctionService,
private platformUtilsService: PlatformUtilsService,
private environmentService: EnvironmentService
private environmentService: EnvironmentService,
private sendApiService: SendApiService
) {
super(cryptoService);
}
@@ -84,7 +86,7 @@ export class SendReceiveCommand extends DownloadCommand {
process.stdout.write(response?.text?.text);
return Response.success();
case SendType.File: {
const downloadData = await this.apiService.getSendFileDownloadData(
const downloadData = await this.sendApiService.getSendFileDownloadData(
response,
this.sendAccessRequest,
apiUrl
@@ -135,7 +137,11 @@ export class SendReceiveCommand extends DownloadCommand {
key: ArrayBuffer
): Promise<Response | SendAccessView> {
try {
const sendResponse = await this.apiService.postSendAccess(id, this.sendAccessRequest, url);
const sendResponse = await this.sendApiService.postSendAccess(
id,
this.sendAccessRequest,
url
);
const sendAccess = new SendAccess(sendResponse);
this.decKey = await this.cryptoService.makeSendKey(key);

View File

@@ -1,14 +1,15 @@
import { SendService } from "@bitwarden/common/abstractions/send.service";
import { SendApiService } from "@bitwarden/common/abstractions/send/send-api.service.abstraction";
import { SendService } from "@bitwarden/common/abstractions/send/send.service.abstraction";
import { Response } from "../../models/response";
import { SendResponse } from "../../models/response/send.response";
export class SendRemovePasswordCommand {
constructor(private sendService: SendService) {}
constructor(private sendService: SendService, private sendApiService: SendApiService) {}
async run(id: string) {
try {
await this.sendService.removePasswordWithServer(id);
await this.sendApiService.removePassword(id);
const updatedSend = await this.sendService.get(id);
const decSend = await updatedSend.decrypt();

View File

@@ -133,9 +133,10 @@ export class ServeCommand {
this.sendCreateCommand = new SendCreateCommand(
this.main.sendService,
this.main.stateService,
this.main.environmentService
this.main.environmentService,
this.main.sendApiService
);
this.sendDeleteCommand = new SendDeleteCommand(this.main.sendService);
this.sendDeleteCommand = new SendDeleteCommand(this.main.sendService, this.main.sendApiService);
this.sendGetCommand = new SendGetCommand(
this.main.sendService,
this.main.environmentService,
@@ -145,14 +146,18 @@ export class ServeCommand {
this.sendEditCommand = new SendEditCommand(
this.main.sendService,
this.main.stateService,
this.sendGetCommand
this.sendGetCommand,
this.main.sendApiService
);
this.sendListCommand = new SendListCommand(
this.main.sendService,
this.main.environmentService,
this.main.searchService
);
this.sendRemovePasswordCommand = new SendRemovePasswordCommand(this.main.sendService);
this.sendRemovePasswordCommand = new SendRemovePasswordCommand(
this.main.sendService,
this.main.sendApiService
);
}
async run(options: program.OptionValues) {