diff --git a/libs/tools/export/vault-export/vault-export-core/src/index.ts b/libs/tools/export/vault-export/vault-export-core/src/index.ts index 46166750ad7..181b4e4b23c 100644 --- a/libs/tools/export/vault-export/vault-export-core/src/index.ts +++ b/libs/tools/export/vault-export/vault-export-core/src/index.ts @@ -7,3 +7,4 @@ export * from "./services/org-vault-export.service"; export * from "./services/individual-vault-export.service.abstraction"; export * from "./services/individual-vault-export.service"; export * from "./services/export-helper"; +export * from "./services/api"; diff --git a/libs/tools/export/vault-export/vault-export-core/src/services/api/index.ts b/libs/tools/export/vault-export/vault-export-core/src/services/api/index.ts new file mode 100644 index 00000000000..5b705a93e9a --- /dev/null +++ b/libs/tools/export/vault-export/vault-export-core/src/services/api/index.ts @@ -0,0 +1,2 @@ +export * from "./vault-export-api.service.abstraction"; +export * from "./vault-export-api.service"; diff --git a/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.abstraction.ts b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.abstraction.ts new file mode 100644 index 00000000000..ef27e903891 --- /dev/null +++ b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.abstraction.ts @@ -0,0 +1,13 @@ +import { OrganizationExportResponse } from "@bitwarden/common/admin-console/models/response/organization-export.response"; +import { OrganizationId } from "@bitwarden/common/types/guid"; + +export abstract class VaultExportApiServiceAbstraction { + /** + * Retrieves the export data for a specific organization. + * @param organizationId The ID of the organization to export. + * @returns A promise that resolves to the organization export response. + */ + abstract getOrganizationExport( + organizationId: OrganizationId, + ): Promise; +} diff --git a/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.spec.ts b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.spec.ts new file mode 100644 index 00000000000..4399fc5f804 --- /dev/null +++ b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.spec.ts @@ -0,0 +1,32 @@ +import { mock, MockProxy } from "jest-mock-extended"; + +import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { OrganizationId } from "@bitwarden/common/types/guid"; + +import { VaultExportApiService } from "./vault-export-api.service"; + +describe("VaultExportApiService", () => { + let apiServiceMock: MockProxy; + let sut: VaultExportApiService; + + beforeEach(() => { + apiServiceMock = mock(); + sut = new VaultExportApiService(apiServiceMock); + }); + + it("should call apiService.send with correct parameters", async () => { + const orgId: OrganizationId = "test-org-id" as OrganizationId; + const apiResponse = { foo: "bar" }; + apiServiceMock.send.mockResolvedValue(apiResponse); + + await sut.getOrganizationExport(orgId); + + expect(apiServiceMock.send).toHaveBeenCalledWith( + "GET", + `/organizations/${orgId}/export`, + null, + true, + true, + ); + }); +}); diff --git a/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.ts b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.ts new file mode 100644 index 00000000000..fbfd125819d --- /dev/null +++ b/libs/tools/export/vault-export/vault-export-core/src/services/api/vault-export-api.service.ts @@ -0,0 +1,24 @@ +import { ApiService } from "@bitwarden/common/abstractions/api.service"; +import { OrganizationExportResponse } from "@bitwarden/common/admin-console/models/response/organization-export.response"; +import { OrganizationId } from "@bitwarden/common/types/guid"; + +import { VaultExportApiServiceAbstraction } from "./vault-export-api.service.abstraction"; + +/** + * Service for handling vault export API interactions. + * @param apiService - An instance of {@link ApiService} used to make HTTP requests. + */ +export class VaultExportApiService implements VaultExportApiServiceAbstraction { + constructor(private apiService: ApiService) {} + + async getOrganizationExport(organizationId: OrganizationId): Promise { + const r = await this.apiService.send( + "GET", + "/organizations/" + organizationId + "/export", + null, + true, + true, + ); + return new OrganizationExportResponse(r); + } +}