mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
[PS-1884] [TDL-189] [TDL-203] Move libs/node files to CLI and rename per ADR12 (#4069)
* Extract files only used in cli out of libs/node Move commands from libs/node to cli Move program from libs/node to cli Move services from libs/node to cli Move specs from libs/node to cli Naming changes based on ADR 12 Rename commands Rename models/request Rename models/response Remove entries from whitelist-capital-letters.txt * Merge lowDbStorageService into base class Move logic from extended lowdbStorage.service.ts into base-lowdb-storage.service.ts Delete lowdb-storage.service.ts Rename base-lowdb-storage.service.ts to lowdb-storage.service.ts * Merge login.command with base class program.ts - changed import temporarily to make it easier to review Remove passing in clientId, set "cli" when constructing ssoRedirectUri call Remove setting callbacks, use private methods instead Remove i18nService from constructor params Add syncService, keyConnectorService and logoutCallback to constructor Merge successCallback with handleSuccessResponse Remove validatedParams callback and added private method Move options(program.OptionValues) and set in run() Delete login.command.ts * Rename base-login.command.ts to login.command.ts * Merge base.program.ts with program.ts
This commit is contained in:
committed by
GitHub
parent
166e5a747e
commit
80f5a883e0
@@ -1,6 +1,6 @@
|
||||
import { CollectionExport } from "@bitwarden/common/models/export/collection.export";
|
||||
|
||||
import { SelectionReadOnly } from "../selectionReadOnly";
|
||||
import { SelectionReadOnly } from "../selection-read-only";
|
||||
|
||||
export class OrganizationCollectionRequest extends CollectionExport {
|
||||
static template(): OrganizationCollectionRequest {
|
||||
50
apps/cli/src/models/response.ts
Normal file
50
apps/cli/src/models/response.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { BaseResponse } from "./response/base.response";
|
||||
|
||||
export class Response {
|
||||
static error(error: any, data?: any): Response {
|
||||
const res = new Response();
|
||||
res.success = false;
|
||||
if (typeof error === "string") {
|
||||
res.message = error;
|
||||
} else {
|
||||
res.message =
|
||||
error.message != null
|
||||
? error.message
|
||||
: error.toString() === "[object Object]"
|
||||
? JSON.stringify(error)
|
||||
: error.toString();
|
||||
}
|
||||
res.data = data;
|
||||
return res;
|
||||
}
|
||||
|
||||
static notFound(): Response {
|
||||
return Response.error("Not found.");
|
||||
}
|
||||
|
||||
static badRequest(message: string): Response {
|
||||
return Response.error(message);
|
||||
}
|
||||
|
||||
static multipleResults(ids: string[]): Response {
|
||||
let msg =
|
||||
"More than one result was found. Try getting a specific object by `id` instead. " +
|
||||
"The following objects were found:";
|
||||
ids.forEach((id) => {
|
||||
msg += "\n" + id;
|
||||
});
|
||||
return Response.error(msg, ids);
|
||||
}
|
||||
|
||||
static success(data?: BaseResponse): Response {
|
||||
const res = new Response();
|
||||
res.success = true;
|
||||
res.data = data;
|
||||
return res;
|
||||
}
|
||||
|
||||
success: boolean;
|
||||
message: string;
|
||||
errorCode: number;
|
||||
data: BaseResponse;
|
||||
}
|
||||
3
apps/cli/src/models/response/base.response.ts
Normal file
3
apps/cli/src/models/response/base.response.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface BaseResponse {
|
||||
object: string;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import { CipherType } from "@bitwarden/common/enums/cipherType";
|
||||
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
|
||||
import { CipherView } from "@bitwarden/common/models/view/cipher.view";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { AttachmentResponse } from "./attachmentResponse";
|
||||
import { LoginResponse } from "./loginResponse";
|
||||
import { PasswordHistoryResponse } from "./passwordHistoryResponse";
|
||||
import { AttachmentResponse } from "./attachment.response";
|
||||
import { BaseResponse } from "./base.response";
|
||||
import { LoginResponse } from "./login.response";
|
||||
import { PasswordHistoryResponse } from "./password-history.response";
|
||||
|
||||
export class CipherResponse extends CipherWithIdExport implements BaseResponse {
|
||||
object: string;
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CollectionWithIdExport } from "@bitwarden/common/models/export/collection-with-id.export";
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class CollectionResponse extends CollectionWithIdExport implements BaseResponse {
|
||||
object: string;
|
||||
13
apps/cli/src/models/response/file.response.ts
Normal file
13
apps/cli/src/models/response/file.response.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class FileResponse implements BaseResponse {
|
||||
object: string;
|
||||
data: Buffer;
|
||||
fileName: string;
|
||||
|
||||
constructor(data: Buffer, fileName: string) {
|
||||
this.object = "file";
|
||||
this.data = data;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { FolderWithIdExport } from "@bitwarden/common/models/export/folder-with-id.export";
|
||||
import { FolderView } from "@bitwarden/common/models/view/folder.view";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class FolderResponse extends FolderWithIdExport implements BaseResponse {
|
||||
object: string;
|
||||
11
apps/cli/src/models/response/list.response.ts
Normal file
11
apps/cli/src/models/response/list.response.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class ListResponse implements BaseResponse {
|
||||
object: string;
|
||||
data: BaseResponse[];
|
||||
|
||||
constructor(data: BaseResponse[]) {
|
||||
this.object = "list";
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
15
apps/cli/src/models/response/message.response.ts
Normal file
15
apps/cli/src/models/response/message.response.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class MessageResponse implements BaseResponse {
|
||||
object: string;
|
||||
title: string;
|
||||
message: string;
|
||||
raw: string;
|
||||
noColor = false;
|
||||
|
||||
constructor(title: string, message: string) {
|
||||
this.object = "message";
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
|
||||
import { SelectionReadOnly } from "../selectionReadOnly";
|
||||
import { SelectionReadOnly } from "../selection-read-only";
|
||||
|
||||
import { CollectionResponse } from "./collectionResponse";
|
||||
import { CollectionResponse } from "./collection.response";
|
||||
|
||||
export class OrganizationCollectionResponse extends CollectionResponse {
|
||||
groups: SelectionReadOnly[];
|
||||
@@ -1,6 +1,7 @@
|
||||
import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType";
|
||||
import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class OrganizationUserResponse implements BaseResponse {
|
||||
object: string;
|
||||
@@ -1,7 +1,8 @@
|
||||
import { OrganizationUserStatusType } from "@bitwarden/common/enums/organizationUserStatusType";
|
||||
import { OrganizationUserType } from "@bitwarden/common/enums/organizationUserType";
|
||||
import { Organization } from "@bitwarden/common/models/domain/organization";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class OrganizationResponse implements BaseResponse {
|
||||
object: string;
|
||||
@@ -1,9 +1,9 @@
|
||||
import { SendType } from "@bitwarden/common/enums/sendType";
|
||||
import { SendAccessView } from "@bitwarden/common/models/view/send-access.view";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { SendFileResponse } from "./sendFileResponse";
|
||||
import { SendTextResponse } from "./sendTextResponse";
|
||||
import { BaseResponse } from "./base.response";
|
||||
import { SendFileResponse } from "./send-file.response";
|
||||
import { SendTextResponse } from "./send-text.response";
|
||||
|
||||
export class SendAccessResponse implements BaseResponse {
|
||||
static template(): SendAccessResponse {
|
||||
@@ -1,10 +1,10 @@
|
||||
import { SendType } from "@bitwarden/common/enums/sendType";
|
||||
import { Utils } from "@bitwarden/common/misc/utils";
|
||||
import { SendView } from "@bitwarden/common/models/view/send.view";
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
|
||||
import { SendFileResponse } from "./sendFileResponse";
|
||||
import { SendTextResponse } from "./sendTextResponse";
|
||||
import { BaseResponse } from "./base.response";
|
||||
import { SendFileResponse } from "./send-file.response";
|
||||
import { SendTextResponse } from "./send-text.response";
|
||||
|
||||
const dateProperties: string[] = [
|
||||
Utils.nameOf<SendResponse>("deletionDate"),
|
||||
11
apps/cli/src/models/response/string.response.ts
Normal file
11
apps/cli/src/models/response/string.response.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class StringResponse implements BaseResponse {
|
||||
object: string;
|
||||
data: string;
|
||||
|
||||
constructor(data: string) {
|
||||
this.object = "string";
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BaseResponse } from "@bitwarden/node/cli/models/response/baseResponse";
|
||||
import { BaseResponse } from "./base.response";
|
||||
|
||||
export class TemplateResponse implements BaseResponse {
|
||||
object: string;
|
||||
Reference in New Issue
Block a user