diff --git a/src/lib/features/export-import-toggles/export-import-controller.ts b/src/lib/features/export-import-toggles/export-import-controller.ts index 763ce1162b..02e6f94136 100644 --- a/src/lib/features/export-import-toggles/export-import-controller.ts +++ b/src/lib/features/export-import-toggles/export-import-controller.ts @@ -1,7 +1,10 @@ import { Response } from 'express'; import Controller from '../../routes/controller'; import { Logger } from '../../logger'; -import ExportImportService from './export-import-service'; +import ExportImportService, { + IExportService, + IImportService, +} from './export-import-service'; import { OpenApiService } from '../../services'; import { TransactionCreator, @@ -32,32 +35,31 @@ import ApiUser from '../../types/api-user'; class ExportImportController extends Controller { private logger: Logger; - /** @deprecated gradually rolling out exportImportV2 */ - private exportImportService: ExportImportService; + private exportService: IExportService; - /** @deprecated gradually rolling out exportImportV2 */ + /** @deprecated gradually rolling out importService */ private transactionalExportImportService: ( db: UnleashTransaction, - ) => Pick; + ) => IImportService; - private exportImportServiceV2: WithTransactional; + private importService: WithTransactional; private openApiService: OpenApiService; - /** @deprecated gradually rolling out exportImportV2 */ + /** @deprecated gradually rolling out importService */ private readonly startTransaction: TransactionCreator; constructor( config: IUnleashConfig, { - exportImportService, + exportService, transactionalExportImportService, - exportImportServiceV2, + importService, openApiService, }: Pick< IUnleashServices, - | 'exportImportService' - | 'exportImportServiceV2' + | 'exportService' + | 'importService' | 'openApiService' | 'transactionalExportImportService' >, @@ -65,10 +67,10 @@ class ExportImportController extends Controller { ) { super(config); this.logger = config.getLogger('/admin-api/export-import.ts'); - this.exportImportService = exportImportService; + this.exportService = exportService; this.transactionalExportImportService = transactionalExportImportService; - this.exportImportServiceV2 = exportImportServiceV2; + this.importService = importService; this.startTransaction = startTransaction; this.openApiService = openApiService; this.route({ @@ -141,12 +143,7 @@ class ExportImportController extends Controller { const query = req.body; const userName = extractUsername(req); - const useTransactionalDecorator = this.config.flagResolver.isEnabled( - 'transactionalDecorator', - ); - const data = useTransactionalDecorator - ? await this.exportImportServiceV2.export(query, userName) - : await this.exportImportService.export(query, userName); + const data = await this.exportService.export(query, userName); this.openApiService.respondWithValidation( 200, @@ -168,7 +165,7 @@ class ExportImportController extends Controller { 'transactionalDecorator', ); const validation = useTransactionalDecorator - ? await this.exportImportServiceV2.transactional((service) => + ? await this.importService.transactional((service) => service.validate(dto, user), ) : await this.startTransaction(async (tx) => @@ -203,7 +200,7 @@ class ExportImportController extends Controller { ); if (useTransactionalDecorator) { - await this.exportImportServiceV2.transactional((service) => + await this.importService.transactional((service) => service.import(dto, user), ); } else { diff --git a/src/lib/features/export-import-toggles/export-import-service.ts b/src/lib/features/export-import-toggles/export-import-service.ts index 29a7599b59..cd1d141da7 100644 --- a/src/lib/features/export-import-toggles/export-import-service.ts +++ b/src/lib/features/export-import-toggles/export-import-service.ts @@ -50,7 +50,25 @@ import { ImportValidationMessages } from './import-validation-messages'; import { findDuplicates } from '../../util/findDuplicates'; import { FeatureNameCheckResultWithFeaturePattern } from '../feature-toggle/feature-toggle-service'; -export default class ExportImportService { +export type IImportService = { + validate( + dto: ImportTogglesSchema, + user: User, + ): Promise; + + import(dto: ImportTogglesSchema, user: User): Promise; +}; + +export type IExportService = { + export( + query: ExportQuerySchema, + userName: string, + ): Promise; +}; + +export default class ExportImportService + implements IExportService, IImportService +{ private logger: Logger; private toggleStore: IFeatureToggleStore; diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index b825d15ab0..3c21322be6 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -299,7 +299,7 @@ export const createServices = ( const exportImportService = db ? createExportImportTogglesService(db, config) : createFakeExportImportTogglesService(config); - const exportImportServiceV2 = db + const importService = db ? withTransactional(deferredExportImportTogglesService(config), db) : withFakeTransactional(createFakeExportImportTogglesService(config)); const transactionalExportImportService = (txDb: Knex.Transaction) => @@ -403,9 +403,9 @@ export const createServices = ( instanceStatsService, favoritesService, maintenanceService, - exportImportService, + exportService: exportImportService, transactionalExportImportService, - exportImportServiceV2, + importService, schedulerService, configurationRevisionService, transactionalFeatureToggleService, diff --git a/src/lib/types/services.ts b/src/lib/types/services.ts index 10df0ed368..1aaadcba9e 100644 --- a/src/lib/types/services.ts +++ b/src/lib/types/services.ts @@ -39,7 +39,10 @@ import MaintenanceService from '../services/maintenance-service'; import { AccountService } from '../services/account-service'; import { SchedulerService } from '../services/scheduler-service'; import { Knex } from 'knex'; -import ExportImportService from '../features/export-import-toggles/export-import-service'; +import { + IExportService, + IImportService, +} from '../features/export-import-toggles/export-import-service'; import { ISegmentService } from '../segments/segment-service-interface'; import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service'; import EventAnnouncerService from 'lib/services/event-announcer-service'; @@ -89,16 +92,13 @@ export interface IUnleashServices { instanceStatsService: InstanceStatsService; favoritesService: FavoritesService; maintenanceService: MaintenanceService; - /** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */ - exportImportService: ExportImportService; - exportImportServiceV2: WithTransactional; + exportService: IExportService; + importService: WithTransactional; configurationRevisionService: ConfigurationRevisionService; schedulerService: SchedulerService; eventAnnouncerService: EventAnnouncerService; /** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */ - transactionalExportImportService: ( - db: Knex.Transaction, - ) => Pick; + transactionalExportImportService: (db: Knex.Transaction) => IImportService; transactionalFeatureToggleService: ( db: Knex.Transaction, ) => FeatureToggleService;