(
object: string,
id: string,
requestJson: any,
cmdOptions: Record<string, any>,
)
| 49 | ) {} |
| 50 | |
| 51 | async run( |
| 52 | object: string, |
| 53 | id: string, |
| 54 | requestJson: any, |
| 55 | cmdOptions: Record<string, any>, |
| 56 | ): Promise<Response> { |
| 57 | if (process.env.BW_SERVE !== "true" && (requestJson == null || requestJson === "")) { |
| 58 | requestJson = await CliUtils.readStdin(); |
| 59 | } |
| 60 | |
| 61 | if (requestJson == null || requestJson === "") { |
| 62 | return Response.badRequest("`requestJson` was not provided."); |
| 63 | } |
| 64 | |
| 65 | let req: any = null; |
| 66 | if (typeof requestJson !== "string") { |
| 67 | req = requestJson; |
| 68 | } else { |
| 69 | try { |
| 70 | const reqJson = Buffer.from(requestJson, "base64").toString(); |
| 71 | req = JSON.parse(reqJson); |
| 72 | // FIXME: Remove when updating file. Eslint update |
| 73 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 74 | } catch (e) { |
| 75 | return Response.badRequest("Error parsing the encoded request data."); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (id != null) { |
| 80 | id = id.toLowerCase(); |
| 81 | } |
| 82 | |
| 83 | const normalizedOptions = new Options(cmdOptions); |
| 84 | switch (object.toLowerCase()) { |
| 85 | case "item": |
| 86 | return await this.editCipher(id, req); |
| 87 | case "item-collections": |
| 88 | return await this.editCipherCollections(id, req); |
| 89 | case "folder": |
| 90 | return await this.editFolder(id, req); |
| 91 | case "org-collection": |
| 92 | return await this.editOrganizationCollection(id, req, normalizedOptions); |
| 93 | default: |
| 94 | return Response.badRequest("Unknown object."); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | private async editCipher(id: string, req: CipherExport) { |
| 99 | const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); |
no test coverage detected