From b7d38f0f72767312dbe67b197111ebee4b374116 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Mon, 30 Jan 2023 20:03:12 +0100 Subject: [PATCH] [PS-2320] Import API service refactor (#4529) * Extract import methods from ApiService Removed methods from ApiService impl and abstraction Create import-api.service impl and abstraction Moved import.service into abstractions/import/import.service.abstraction Moved import.service into services/import/import.service Change imports to use new services * Fix import for tests * Fix imports for CLI * Fix imports for web * Fix ModuleImports and dependencies * Mark ImportApiService methods as async --- apps/cli/src/bw.ts | 9 +- apps/cli/src/commands/import.command.ts | 2 +- .../import-export/org-import-export.module.ts | 13 +- .../import-export/org-import.component.ts | 2 +- .../import-export/import-export.module.ts | 13 +- .../tools/import-export/import.component.ts | 2 +- .../spec/services/import.service.spec.ts | 10 +- libs/common/src/abstractions/api.service.ts | 7 - .../import/import-api.service.abstraction.ts | 10 ++ .../import.service.abstraction.ts} | 6 +- libs/common/src/services/api.service.ts | 19 -- .../src/services/import/import-api.service.ts | 25 +++ .../services/{ => import}/import.service.ts | 164 +++++++++--------- 13 files changed, 155 insertions(+), 127 deletions(-) create mode 100644 libs/common/src/abstractions/import/import-api.service.abstraction.ts rename libs/common/src/abstractions/{import.service.ts => import/import.service.abstraction.ts} (70%) create mode 100644 libs/common/src/services/import/import-api.service.ts rename libs/common/src/services/{ => import}/import.service.ts (61%) diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 4395d935ce..429b8e5388 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -5,6 +5,7 @@ import * as program from "commander"; import * as jsdom from "jsdom"; import { InternalFolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; +import { ImportApiServiceAbstraction } from "@bitwarden/common/abstractions/import/import-api.service.abstraction"; import { OrganizationUserService } from "@bitwarden/common/abstractions/organization-user/organization-user.service"; import { OrganizationApiServiceAbstraction } from "@bitwarden/common/abstractions/organization/organization-api.service.abstraction"; import { ClientType } from "@bitwarden/common/enums/clientType"; @@ -27,7 +28,8 @@ import { ExportService } from "@bitwarden/common/services/export.service"; import { FileUploadService } from "@bitwarden/common/services/fileUpload.service"; import { FolderApiService } from "@bitwarden/common/services/folder/folder-api.service"; import { FolderService } from "@bitwarden/common/services/folder/folder.service"; -import { ImportService } from "@bitwarden/common/services/import.service"; +import { ImportApiService } from "@bitwarden/common/services/import/import-api.service"; +import { ImportService } from "@bitwarden/common/services/import/import.service"; import { KeyConnectorService } from "@bitwarden/common/services/keyConnector.service"; import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service"; import { NoopMessagingService } from "@bitwarden/common/services/noopMessaging.service"; @@ -94,6 +96,7 @@ export class Main { containerService: ContainerService; auditService: AuditService; importService: ImportService; + importApiService: ImportApiServiceAbstraction; exportService: ExportService; searchService: SearchService; cryptoFunctionService: NodeCryptoFunctionService; @@ -339,10 +342,12 @@ export class Main { this.totpService = new TotpService(this.cryptoFunctionService, this.logService); + this.importApiService = new ImportApiService(this.apiService); + this.importService = new ImportService( this.cipherService, this.folderService, - this.apiService, + this.importApiService, this.i18nService, this.collectionService, this.cryptoService diff --git a/apps/cli/src/commands/import.command.ts b/apps/cli/src/commands/import.command.ts index 97145771ef..bc753ffc7a 100644 --- a/apps/cli/src/commands/import.command.ts +++ b/apps/cli/src/commands/import.command.ts @@ -1,7 +1,7 @@ import * as program from "commander"; import * as inquirer from "inquirer"; -import { ImportService } from "@bitwarden/common/abstractions/import.service"; +import { ImportService } from "@bitwarden/common/abstractions/import/import.service.abstraction"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { ImportType } from "@bitwarden/common/enums/importOptions"; import { Importer } from "@bitwarden/common/importers/importer"; diff --git a/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts b/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts index 650363300b..3140050262 100644 --- a/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts +++ b/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts @@ -6,8 +6,10 @@ import { CollectionService } from "@bitwarden/common/abstractions/collection.ser import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.service"; -import { ImportService } from "@bitwarden/common/services/import.service"; +import { ImportApiServiceAbstraction } from "@bitwarden/common/abstractions/import/import-api.service.abstraction"; +import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import/import.service.abstraction"; +import { ImportApiService } from "@bitwarden/common/services/import/import-api.service"; +import { ImportService } from "@bitwarden/common/services/import/import.service"; import { LooseComponentsModule, SharedModule } from "../../../shared"; @@ -19,13 +21,18 @@ import { OrganizationImportComponent } from "./org-import.component"; imports: [SharedModule, LooseComponentsModule, OrganizationImportExportRoutingModule], declarations: [OrganizationImportComponent, OrganizationExportComponent], providers: [ + { + provide: ImportApiServiceAbstraction, + useClass: ImportApiService, + deps: [ApiService], + }, { provide: ImportServiceAbstraction, useClass: ImportService, deps: [ CipherService, FolderService, - ApiService, + ImportApiServiceAbstraction, I18nService, CollectionService, CryptoService, diff --git a/apps/web/src/app/organizations/tools/import-export/org-import.component.ts b/apps/web/src/app/organizations/tools/import-export/org-import.component.ts index 2e70908cd8..cf1935c85f 100644 --- a/apps/web/src/app/organizations/tools/import-export/org-import.component.ts +++ b/apps/web/src/app/organizations/tools/import-export/org-import.component.ts @@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { ImportService } from "@bitwarden/common/abstractions/import.service"; +import { ImportService } from "@bitwarden/common/abstractions/import/import.service.abstraction"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; diff --git a/apps/web/src/app/tools/import-export/import-export.module.ts b/apps/web/src/app/tools/import-export/import-export.module.ts index 25eab99cd3..1d33cb1210 100644 --- a/apps/web/src/app/tools/import-export/import-export.module.ts +++ b/apps/web/src/app/tools/import-export/import-export.module.ts @@ -6,8 +6,10 @@ import { CollectionService } from "@bitwarden/common/abstractions/collection.ser import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.service"; -import { ImportService } from "@bitwarden/common/services/import.service"; +import { ImportApiServiceAbstraction } from "@bitwarden/common/abstractions/import/import-api.service.abstraction"; +import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import/import.service.abstraction"; +import { ImportApiService } from "@bitwarden/common/services/import/import-api.service"; +import { ImportService } from "@bitwarden/common/services/import/import.service"; import { LooseComponentsModule, SharedModule } from "../../shared"; @@ -20,13 +22,18 @@ import { ImportComponent } from "./import.component"; imports: [SharedModule, LooseComponentsModule, ImportExportRoutingModule], declarations: [ImportComponent, ExportComponent, FilePasswordPromptComponent], providers: [ + { + provide: ImportApiServiceAbstraction, + useClass: ImportApiService, + deps: [ApiService], + }, { provide: ImportServiceAbstraction, useClass: ImportService, deps: [ CipherService, FolderService, - ApiService, + ImportApiServiceAbstraction, I18nService, CollectionService, CryptoService, diff --git a/apps/web/src/app/tools/import-export/import.component.ts b/apps/web/src/app/tools/import-export/import.component.ts index da9a27542c..98310120f9 100644 --- a/apps/web/src/app/tools/import-export/import.component.ts +++ b/apps/web/src/app/tools/import-export/import.component.ts @@ -6,7 +6,7 @@ import Swal, { SweetAlertIcon } from "sweetalert2"; import { ModalService } from "@bitwarden/angular/services/modal.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { ImportService } from "@bitwarden/common/abstractions/import.service"; +import { ImportService } from "@bitwarden/common/abstractions/import/import.service.abstraction"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction"; diff --git a/libs/common/spec/services/import.service.spec.ts b/libs/common/spec/services/import.service.spec.ts index c0ce1d0f4f..e1e1c4914f 100644 --- a/libs/common/spec/services/import.service.spec.ts +++ b/libs/common/spec/services/import.service.spec.ts @@ -1,22 +1,22 @@ // eslint-disable-next-line no-restricted-imports import { Substitute, SubstituteOf } from "@fluffy-spoon/substitute"; -import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { CipherService } from "@bitwarden/common/abstractions/cipher.service"; import { CollectionService } from "@bitwarden/common/abstractions/collection.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; +import { ImportApiServiceAbstraction } from "@bitwarden/common/abstractions/import/import-api.service.abstraction"; import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwarden-password-protected-importer"; import { Importer } from "@bitwarden/common/importers/importer"; import { Utils } from "@bitwarden/common/misc/utils"; -import { ImportService } from "@bitwarden/common/services/import.service"; +import { ImportService } from "@bitwarden/common/services/import/import.service"; describe("ImportService", () => { let importService: ImportService; let cipherService: SubstituteOf; let folderService: SubstituteOf; - let apiService: SubstituteOf; + let importApiService: SubstituteOf; let i18nService: SubstituteOf; let collectionService: SubstituteOf; let cryptoService: SubstituteOf; @@ -24,7 +24,7 @@ describe("ImportService", () => { beforeEach(() => { cipherService = Substitute.for(); folderService = Substitute.for(); - apiService = Substitute.for(); + importApiService = Substitute.for(); i18nService = Substitute.for(); collectionService = Substitute.for(); cryptoService = Substitute.for(); @@ -32,7 +32,7 @@ describe("ImportService", () => { importService = new ImportService( cipherService, folderService, - apiService, + importApiService, i18nService, collectionService, cryptoService diff --git a/libs/common/src/abstractions/api.service.ts b/libs/common/src/abstractions/api.service.ts index 7fc2514acc..edf0092df9 100644 --- a/libs/common/src/abstractions/api.service.ts +++ b/libs/common/src/abstractions/api.service.ts @@ -27,8 +27,6 @@ import { IapCheckRequest } from "../models/request/iap-check.request"; import { PasswordTokenRequest } from "../models/request/identity-token/password-token.request"; import { SsoTokenRequest } from "../models/request/identity-token/sso-token.request"; import { UserApiTokenRequest } from "../models/request/identity-token/user-api-token.request"; -import { ImportCiphersRequest } from "../models/request/import-ciphers.request"; -import { ImportOrganizationCiphersRequest } from "../models/request/import-organization-ciphers.request"; import { KdfRequest } from "../models/request/kdf.request"; import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user-key.request"; import { KeysRequest } from "../models/request/keys.request"; @@ -260,11 +258,6 @@ export abstract class ApiService { putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise; putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise; postPurgeCiphers: (request: SecretVerificationRequest, organizationId?: string) => Promise; - postImportCiphers: (request: ImportCiphersRequest) => Promise; - postImportOrganizationCiphers: ( - organizationId: string, - request: ImportOrganizationCiphersRequest - ) => Promise; putDeleteCipher: (id: string) => Promise; putDeleteCipherAdmin: (id: string) => Promise; putDeleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; diff --git a/libs/common/src/abstractions/import/import-api.service.abstraction.ts b/libs/common/src/abstractions/import/import-api.service.abstraction.ts new file mode 100644 index 0000000000..041284d57a --- /dev/null +++ b/libs/common/src/abstractions/import/import-api.service.abstraction.ts @@ -0,0 +1,10 @@ +import { ImportCiphersRequest } from "../../models/request/import-ciphers.request"; +import { ImportOrganizationCiphersRequest } from "../../models/request/import-organization-ciphers.request"; + +export abstract class ImportApiServiceAbstraction { + postImportCiphers: (request: ImportCiphersRequest) => Promise; + postImportOrganizationCiphers: ( + organizationId: string, + request: ImportOrganizationCiphersRequest + ) => Promise; +} diff --git a/libs/common/src/abstractions/import.service.ts b/libs/common/src/abstractions/import/import.service.abstraction.ts similarity index 70% rename from libs/common/src/abstractions/import.service.ts rename to libs/common/src/abstractions/import/import.service.abstraction.ts index e0acb0becc..1c301856b5 100644 --- a/libs/common/src/abstractions/import.service.ts +++ b/libs/common/src/abstractions/import/import.service.abstraction.ts @@ -1,6 +1,6 @@ -import { ImportOption, ImportType } from "../enums/importOptions"; -import { ImportError } from "../importers/import-error"; -import { Importer } from "../importers/importer"; +import { ImportOption, ImportType } from "../../enums/importOptions"; +import { ImportError } from "../../importers/import-error"; +import { Importer } from "../../importers/importer"; export abstract class ImportService { featuredImportOptions: readonly ImportOption[]; diff --git a/libs/common/src/services/api.service.ts b/libs/common/src/services/api.service.ts index a65bd8ab04..4412fcd75b 100644 --- a/libs/common/src/services/api.service.ts +++ b/libs/common/src/services/api.service.ts @@ -35,8 +35,6 @@ import { PasswordTokenRequest } from "../models/request/identity-token/password- import { SsoTokenRequest } from "../models/request/identity-token/sso-token.request"; import { TokenTwoFactorRequest } from "../models/request/identity-token/token-two-factor.request"; import { UserApiTokenRequest } from "../models/request/identity-token/user-api-token.request"; -import { ImportCiphersRequest } from "../models/request/import-ciphers.request"; -import { ImportOrganizationCiphersRequest } from "../models/request/import-organization-ciphers.request"; import { KdfRequest } from "../models/request/kdf.request"; import { KeyConnectorUserKeyRequest } from "../models/request/key-connector-user-key.request"; import { KeysRequest } from "../models/request/keys.request"; @@ -662,23 +660,6 @@ export class ApiService implements ApiServiceAbstraction { return this.send("POST", path, request, true, false); } - postImportCiphers(request: ImportCiphersRequest): Promise { - return this.send("POST", "/ciphers/import", request, true, false); - } - - postImportOrganizationCiphers( - organizationId: string, - request: ImportOrganizationCiphersRequest - ): Promise { - return this.send( - "POST", - "/ciphers/import-organization?organizationId=" + organizationId, - request, - true, - false - ); - } - putDeleteCipher(id: string): Promise { return this.send("PUT", "/ciphers/" + id + "/delete", null, true, false); } diff --git a/libs/common/src/services/import/import-api.service.ts b/libs/common/src/services/import/import-api.service.ts new file mode 100644 index 0000000000..80342b1d1f --- /dev/null +++ b/libs/common/src/services/import/import-api.service.ts @@ -0,0 +1,25 @@ +import { ApiService } from "../../abstractions/api.service"; +import { ImportApiServiceAbstraction } from "../../abstractions/import/import-api.service.abstraction"; +import { ImportCiphersRequest } from "../../models/request/import-ciphers.request"; +import { ImportOrganizationCiphersRequest } from "../../models/request/import-organization-ciphers.request"; + +export class ImportApiService implements ImportApiServiceAbstraction { + constructor(private apiService: ApiService) {} + + async postImportCiphers(request: ImportCiphersRequest): Promise { + return await this.apiService.send("POST", "/ciphers/import", request, true, false); + } + + async postImportOrganizationCiphers( + organizationId: string, + request: ImportOrganizationCiphersRequest + ): Promise { + return await this.apiService.send( + "POST", + "/ciphers/import-organization?organizationId=" + organizationId, + request, + true, + false + ); + } +} diff --git a/libs/common/src/services/import.service.ts b/libs/common/src/services/import/import.service.ts similarity index 61% rename from libs/common/src/services/import.service.ts rename to libs/common/src/services/import/import.service.ts index d7c8cd1237..1b2c7846ce 100644 --- a/libs/common/src/services/import.service.ts +++ b/libs/common/src/services/import/import.service.ts @@ -1,87 +1,87 @@ -import { ApiService } from "../abstractions/api.service"; -import { CipherService } from "../abstractions/cipher.service"; -import { CollectionService } from "../abstractions/collection.service"; -import { CryptoService } from "../abstractions/crypto.service"; -import { FolderService } from "../abstractions/folder/folder.service.abstraction"; -import { I18nService } from "../abstractions/i18n.service"; -import { ImportService as ImportServiceAbstraction } from "../abstractions/import.service"; -import { CipherType } from "../enums/cipherType"; +import { CipherService } from "../../abstractions/cipher.service"; +import { CollectionService } from "../../abstractions/collection.service"; +import { CryptoService } from "../../abstractions/crypto.service"; +import { FolderService } from "../../abstractions/folder/folder.service.abstraction"; +import { I18nService } from "../../abstractions/i18n.service"; +import { ImportApiServiceAbstraction } from "../../abstractions/import/import-api.service.abstraction"; +import { ImportService as ImportServiceAbstraction } from "../../abstractions/import/import.service.abstraction"; +import { CipherType } from "../../enums/cipherType"; import { featuredImportOptions, ImportOption, ImportType, regularImportOptions, -} from "../enums/importOptions"; -import { AscendoCsvImporter } from "../importers/ascendo-csv-importer"; -import { AvastCsvImporter } from "../importers/avast-csv-importer"; -import { AvastJsonImporter } from "../importers/avast-json-importer"; -import { AviraCsvImporter } from "../importers/avira-csv-importer"; -import { BitwardenCsvImporter } from "../importers/bitwarden-csv-importer"; -import { BitwardenJsonImporter } from "../importers/bitwarden-json-importer"; -import { BitwardenPasswordProtectedImporter } from "../importers/bitwarden-password-protected-importer"; -import { BlackBerryCsvImporter } from "../importers/blackberry-csv-importer"; -import { BlurCsvImporter } from "../importers/blur-csv-importer"; -import { ButtercupCsvImporter } from "../importers/buttercup-csv-importer"; -import { ChromeCsvImporter } from "../importers/chrome-csv-importer"; -import { ClipperzHtmlImporter } from "../importers/clipperz-html-importer"; -import { CodebookCsvImporter } from "../importers/codebook-csv-importer"; -import { DashlaneCsvImporter } from "../importers/dashlane/dashlane-csv-importer"; -import { DashlaneJsonImporter } from "../importers/dashlane/dashlane-json-importer"; -import { EncryptrCsvImporter } from "../importers/encryptr-csv-importer"; -import { EnpassCsvImporter } from "../importers/enpass/enpass-csv-importer"; -import { EnpassJsonImporter } from "../importers/enpass/enpass-json-importer"; -import { FirefoxCsvImporter } from "../importers/firefox-csv-importer"; -import { FSecureFskImporter } from "../importers/fsecure/fsecure-fsk-importer"; -import { GnomeJsonImporter } from "../importers/gnome-json-importer"; -import { ImportError } from "../importers/import-error"; -import { Importer } from "../importers/importer"; -import { KasperskyTxtImporter } from "../importers/kaspersky-txt-importer"; -import { KeePass2XmlImporter } from "../importers/keepass2-xml-importer"; -import { KeePassXCsvImporter } from "../importers/keepassx-csv-importer"; -import { KeeperCsvImporter } from "../importers/keeper/keeper-csv-importer"; -import { LastPassCsvImporter } from "../importers/lastpass-csv-importer"; -import { LogMeOnceCsvImporter } from "../importers/logmeonce-csv-importer"; -import { MeldiumCsvImporter } from "../importers/meldium-csv-importer"; -import { MSecureCsvImporter } from "../importers/msecure-csv-importer"; -import { MykiCsvImporter } from "../importers/myki-csv-importer"; -import { NordPassCsvImporter } from "../importers/nordpass-csv-importer"; -import { OnePassword1PifImporter } from "../importers/onepassword/onepassword-1pif-importer"; -import { OnePassword1PuxImporter } from "../importers/onepassword/onepassword-1pux-importer"; -import { OnePasswordMacCsvImporter } from "../importers/onepassword/onepassword-mac-csv-importer"; -import { OnePasswordWinCsvImporter } from "../importers/onepassword/onepassword-win-csv-importer"; -import { PadlockCsvImporter } from "../importers/padlock-csv-importer"; -import { PassKeepCsvImporter } from "../importers/passkeep-csv-importer"; -import { PasskyJsonImporter } from "../importers/passky/passky-json-importer"; -import { PassmanJsonImporter } from "../importers/passman-json-importer"; -import { PasspackCsvImporter } from "../importers/passpack-csv-importer"; -import { PasswordAgentCsvImporter } from "../importers/passwordagent-csv-importer"; -import { PasswordBossJsonImporter } from "../importers/passwordboss-json-importer"; -import { PasswordDragonXmlImporter } from "../importers/passworddragon-xml-importer"; -import { PasswordSafeXmlImporter } from "../importers/passwordsafe-xml-importer"; -import { PasswordWalletTxtImporter } from "../importers/passwordwallet-txt-importer"; -import { PsonoJsonImporter } from "../importers/psono/psono-json-importer"; -import { RememBearCsvImporter } from "../importers/remembear-csv-importer"; -import { RoboFormCsvImporter } from "../importers/roboform-csv-importer"; -import { SafariCsvImporter } from "../importers/safari-csv-importer"; -import { SafeInCloudXmlImporter } from "../importers/safeincloud-xml-importer"; -import { SaferPassCsvImporter } from "../importers/saferpass-csv-importer"; -import { SecureSafeCsvImporter } from "../importers/securesafe-csv-importer"; -import { SplashIdCsvImporter } from "../importers/splashid-csv-importer"; -import { StickyPasswordXmlImporter } from "../importers/stickypassword-xml-importer"; -import { TrueKeyCsvImporter } from "../importers/truekey-csv-importer"; -import { UpmCsvImporter } from "../importers/upm-csv-importer"; -import { YotiCsvImporter } from "../importers/yoti-csv-importer"; -import { ZohoVaultCsvImporter } from "../importers/zohovault-csv-importer"; -import { Utils } from "../misc/utils"; -import { ImportResult } from "../models/domain/import-result"; -import { CipherRequest } from "../models/request/cipher.request"; -import { CollectionRequest } from "../models/request/collection.request"; -import { FolderRequest } from "../models/request/folder.request"; -import { ImportCiphersRequest } from "../models/request/import-ciphers.request"; -import { ImportOrganizationCiphersRequest } from "../models/request/import-organization-ciphers.request"; -import { KvpRequest } from "../models/request/kvp.request"; -import { ErrorResponse } from "../models/response/error.response"; -import { CipherView } from "../models/view/cipher.view"; +} from "../../enums/importOptions"; +import { AscendoCsvImporter } from "../../importers/ascendo-csv-importer"; +import { AvastCsvImporter } from "../../importers/avast-csv-importer"; +import { AvastJsonImporter } from "../../importers/avast-json-importer"; +import { AviraCsvImporter } from "../../importers/avira-csv-importer"; +import { BitwardenCsvImporter } from "../../importers/bitwarden-csv-importer"; +import { BitwardenJsonImporter } from "../../importers/bitwarden-json-importer"; +import { BitwardenPasswordProtectedImporter } from "../../importers/bitwarden-password-protected-importer"; +import { BlackBerryCsvImporter } from "../../importers/blackberry-csv-importer"; +import { BlurCsvImporter } from "../../importers/blur-csv-importer"; +import { ButtercupCsvImporter } from "../../importers/buttercup-csv-importer"; +import { ChromeCsvImporter } from "../../importers/chrome-csv-importer"; +import { ClipperzHtmlImporter } from "../../importers/clipperz-html-importer"; +import { CodebookCsvImporter } from "../../importers/codebook-csv-importer"; +import { DashlaneCsvImporter } from "../../importers/dashlane/dashlane-csv-importer"; +import { DashlaneJsonImporter } from "../../importers/dashlane/dashlane-json-importer"; +import { EncryptrCsvImporter } from "../../importers/encryptr-csv-importer"; +import { EnpassCsvImporter } from "../../importers/enpass/enpass-csv-importer"; +import { EnpassJsonImporter } from "../../importers/enpass/enpass-json-importer"; +import { FirefoxCsvImporter } from "../../importers/firefox-csv-importer"; +import { FSecureFskImporter } from "../../importers/fsecure/fsecure-fsk-importer"; +import { GnomeJsonImporter } from "../../importers/gnome-json-importer"; +import { ImportError } from "../../importers/import-error"; +import { Importer } from "../../importers/importer"; +import { KasperskyTxtImporter } from "../../importers/kaspersky-txt-importer"; +import { KeePass2XmlImporter } from "../../importers/keepass2-xml-importer"; +import { KeePassXCsvImporter } from "../../importers/keepassx-csv-importer"; +import { KeeperCsvImporter } from "../../importers/keeper/keeper-csv-importer"; +import { LastPassCsvImporter } from "../../importers/lastpass-csv-importer"; +import { LogMeOnceCsvImporter } from "../../importers/logmeonce-csv-importer"; +import { MeldiumCsvImporter } from "../../importers/meldium-csv-importer"; +import { MSecureCsvImporter } from "../../importers/msecure-csv-importer"; +import { MykiCsvImporter } from "../../importers/myki-csv-importer"; +import { NordPassCsvImporter } from "../../importers/nordpass-csv-importer"; +import { OnePassword1PifImporter } from "../../importers/onepassword/onepassword-1pif-importer"; +import { OnePassword1PuxImporter } from "../../importers/onepassword/onepassword-1pux-importer"; +import { OnePasswordMacCsvImporter } from "../../importers/onepassword/onepassword-mac-csv-importer"; +import { OnePasswordWinCsvImporter } from "../../importers/onepassword/onepassword-win-csv-importer"; +import { PadlockCsvImporter } from "../../importers/padlock-csv-importer"; +import { PassKeepCsvImporter } from "../../importers/passkeep-csv-importer"; +import { PasskyJsonImporter } from "../../importers/passky/passky-json-importer"; +import { PassmanJsonImporter } from "../../importers/passman-json-importer"; +import { PasspackCsvImporter } from "../../importers/passpack-csv-importer"; +import { PasswordAgentCsvImporter } from "../../importers/passwordagent-csv-importer"; +import { PasswordBossJsonImporter } from "../../importers/passwordboss-json-importer"; +import { PasswordDragonXmlImporter } from "../../importers/passworddragon-xml-importer"; +import { PasswordSafeXmlImporter } from "../../importers/passwordsafe-xml-importer"; +import { PasswordWalletTxtImporter } from "../../importers/passwordwallet-txt-importer"; +import { PsonoJsonImporter } from "../../importers/psono/psono-json-importer"; +import { RememBearCsvImporter } from "../../importers/remembear-csv-importer"; +import { RoboFormCsvImporter } from "../../importers/roboform-csv-importer"; +import { SafariCsvImporter } from "../../importers/safari-csv-importer"; +import { SafeInCloudXmlImporter } from "../../importers/safeincloud-xml-importer"; +import { SaferPassCsvImporter } from "../../importers/saferpass-csv-importer"; +import { SecureSafeCsvImporter } from "../../importers/securesafe-csv-importer"; +import { SplashIdCsvImporter } from "../../importers/splashid-csv-importer"; +import { StickyPasswordXmlImporter } from "../../importers/stickypassword-xml-importer"; +import { TrueKeyCsvImporter } from "../../importers/truekey-csv-importer"; +import { UpmCsvImporter } from "../../importers/upm-csv-importer"; +import { YotiCsvImporter } from "../../importers/yoti-csv-importer"; +import { ZohoVaultCsvImporter } from "../../importers/zohovault-csv-importer"; +import { Utils } from "../../misc/utils"; +import { ImportResult } from "../../models/domain/import-result"; +import { CipherRequest } from "../../models/request/cipher.request"; +import { CollectionRequest } from "../../models/request/collection.request"; +import { FolderRequest } from "../../models/request/folder.request"; +import { ImportCiphersRequest } from "../../models/request/import-ciphers.request"; +import { ImportOrganizationCiphersRequest } from "../../models/request/import-organization-ciphers.request"; +import { KvpRequest } from "../../models/request/kvp.request"; +import { ErrorResponse } from "../../models/response/error.response"; +import { CipherView } from "../../models/view/cipher.view"; export class ImportService implements ImportServiceAbstraction { featuredImportOptions = featuredImportOptions as readonly ImportOption[]; @@ -91,7 +91,7 @@ export class ImportService implements ImportServiceAbstraction { constructor( private cipherService: CipherService, private folderService: FolderService, - private apiService: ApiService, + private importApiService: ImportApiServiceAbstraction, private i18nService: I18nService, private collectionService: CollectionService, private cryptoService: CryptoService @@ -308,7 +308,7 @@ export class ImportService implements ImportServiceAbstraction { request.folderRelationships.push(new KvpRequest(r[0], r[1])) ); } - return await this.apiService.postImportCiphers(request); + return await this.importApiService.postImportCiphers(request); } else { const request = new ImportOrganizationCiphersRequest(); for (let i = 0; i < importResult.ciphers.length; i++) { @@ -328,7 +328,7 @@ export class ImportService implements ImportServiceAbstraction { request.collectionRelationships.push(new KvpRequest(r[0], r[1])) ); } - return await this.apiService.postImportOrganizationCiphers(organizationId, request); + return await this.importApiService.postImportOrganizationCiphers(organizationId, request); } }