From 198d26d992538aeda9ed0f3572521c6904c65b94 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Tue, 5 Nov 2024 11:30:46 +0100 Subject: [PATCH 1/3] feat: export transactional user subscriptions service --- src/lib/features/index.ts | 1 + .../user-subscriptions-service.e2e.test.ts | 4 ++-- .../user-subscriptions/user-subscriptions-service.ts | 2 +- src/lib/services/index.ts | 8 ++++++++ src/lib/types/services.ts | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/lib/features/index.ts b/src/lib/features/index.ts index 5ca09cf4b1c0..8ad9dfbb983c 100644 --- a/src/lib/features/index.ts +++ b/src/lib/features/index.ts @@ -12,3 +12,4 @@ export * from './instance-stats/createInstanceStatsService'; export * from './feature-lifecycle/createFeatureLifecycle'; export * from './playground/createPlaygroundService'; export * from './personal-dashboard/createPersonalDashboardService'; +export * from './user-subscriptions/createUserSubscriptionsService'; diff --git a/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts b/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts index faf9bfff20db..39e5744a2ccd 100644 --- a/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts +++ b/src/lib/features/user-subscriptions/user-subscriptions-service.e2e.test.ts @@ -4,7 +4,7 @@ import { type IUser, TEST_AUDIT_USER, } from '../../types'; -import type UserSubscriptionService from './user-subscriptions-service'; +import type { UserSubscriptionsService } from './user-subscriptions-service'; import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; import { createTestConfig } from '../../../test/config/test-config'; import getLogger from '../../../test/fixtures/no-logger'; @@ -13,7 +13,7 @@ import type { IUserSubscriptionsReadModel } from './user-subscriptions-read-mode let stores: IUnleashStores; let db: ITestDb; -let userSubscriptionService: UserSubscriptionService; +let userSubscriptionService: UserSubscriptionsService; let userSubscriptionsReadModel: IUserSubscriptionsReadModel; let config: IUnleashConfig; let user: IUser; diff --git a/src/lib/features/user-subscriptions/user-subscriptions-service.ts b/src/lib/features/user-subscriptions/user-subscriptions-service.ts index 3e197da2984e..cebd781a930b 100644 --- a/src/lib/features/user-subscriptions/user-subscriptions-service.ts +++ b/src/lib/features/user-subscriptions/user-subscriptions-service.ts @@ -7,7 +7,7 @@ import type { } from './user-unsubscribe-store-type'; import type EventService from '../events/event-service'; -export default class UserSubscriptionService { +export class UserSubscriptionsService { private userUnsubscribeStore: IUserUnsubscribeStore; private eventService: EventService; diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index b624b3070bb3..a38f493ca5e0 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -73,6 +73,7 @@ import { createFeatureLifecycleService, createFeatureToggleService, createProjectService, + createUserSubscriptionsService, } from '../features'; import EventAnnouncerService from './event-announcer-service'; import { createGroupService } from '../features/group/createGroupService'; @@ -127,6 +128,7 @@ import { createProjectInsightsService, } from '../features/project-insights/createProjectInsightsService'; import { JobService } from '../features/scheduler/job-service'; +import { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service'; import { JobStore } from '../features/scheduler/job-store'; import { FeatureLifecycleService } from '../features/feature-lifecycle/feature-lifecycle-service'; import { createFakeFeatureLifecycleService } from '../features/feature-lifecycle/createFeatureLifecycle'; @@ -426,6 +428,10 @@ export const createServices = ( ? createPersonalDashboardService(db, config, stores) : createFakePersonalDashboardService(config); + const transactionalUserSubscriptionsService = db + ? withTransactional(createUserSubscriptionsService(config), db) + : withFakeTransactional(createUserSubscriptionsService(config)); + return { transactionalAccessService, accessService, @@ -492,6 +498,7 @@ export const createServices = ( onboardingService, personalDashboardService, projectStatusService, + transactionalUserSubscriptionsService, }; }; @@ -544,4 +551,5 @@ export { OnboardingService, PersonalDashboardService, ProjectStatusService, + UserSubscriptionsService, }; diff --git a/src/lib/types/services.ts b/src/lib/types/services.ts index e217abd570b8..3716314a377e 100644 --- a/src/lib/types/services.ts +++ b/src/lib/types/services.ts @@ -58,6 +58,7 @@ import type { IntegrationEventsService } from '../features/integration-events/in import type { OnboardingService } from '../features/onboarding/onboarding-service'; import type { PersonalDashboardService } from '../features/personal-dashboard/personal-dashboard-service'; import type { ProjectStatusService } from '../features/project-status/project-status-service'; +import type { UserSubscriptionsService } from '../features/user-subscriptions/user-subscriptions-service'; export interface IUnleashServices { transactionalAccessService: WithTransactional; @@ -128,4 +129,5 @@ export interface IUnleashServices { onboardingService: OnboardingService; personalDashboardService: PersonalDashboardService; projectStatusService: ProjectStatusService; + transactionalUserSubscriptionsService: WithTransactional; } From b1c9dfa998d0bfdf8625cfd781b3b295329696f1 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Tue, 5 Nov 2024 11:41:30 +0100 Subject: [PATCH 2/3] feat: export user subscriptions service --- .../user-subscriptions/createUserSubscriptionsService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts index b7dca58b6c40..7579fd46e007 100644 --- a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts +++ b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts @@ -1,5 +1,5 @@ import type { Db, IUnleashConfig } from '../../server-impl'; -import UserSubscriptionService from './user-subscriptions-service'; +import { UserSubscriptionsService } from './user-subscriptions-service'; import { UserUnsubscribeStore } from './user-unsubscribe-store'; import { createEventsService, @@ -9,11 +9,11 @@ import { FakeUserUnsubscribeStore } from './fake-user-unsubscribe-store'; export const createUserSubscriptionsService = (config: IUnleashConfig) => - (db: Db): UserSubscriptionService => { + (db: Db): UserSubscriptionsService => { const userUnsubscribeStore = new UserUnsubscribeStore(db); const eventService = createEventsService(db, config); - const userSubscriptionsService = new UserSubscriptionService( + const userSubscriptionsService = new UserSubscriptionsService( { userUnsubscribeStore }, config, eventService, @@ -26,7 +26,7 @@ export const createFakeUserSubscriptionsService = (config: IUnleashConfig) => { const userUnsubscribeStore = new FakeUserUnsubscribeStore(); const eventService = createFakeEventsService(config); - const userSubscriptionsService = new UserSubscriptionService( + const userSubscriptionsService = new UserSubscriptionsService( { userUnsubscribeStore }, config, eventService, From 61f33375b1e64d5d9dbdf02edb13a8f208f2fa77 Mon Sep 17 00:00:00 2001 From: kwasniew Date: Tue, 5 Nov 2024 11:47:13 +0100 Subject: [PATCH 3/3] feat: export user subscriptions service --- .../user-subscriptions/createUserSubscriptionsService.ts | 4 +++- src/lib/services/index.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts index 7579fd46e007..e0a9d5b72254 100644 --- a/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts +++ b/src/lib/features/user-subscriptions/createUserSubscriptionsService.ts @@ -22,7 +22,9 @@ export const createUserSubscriptionsService = return userSubscriptionsService; }; -export const createFakeUserSubscriptionsService = (config: IUnleashConfig) => { +export const createFakeUserSubscriptionsService = ( + config: IUnleashConfig, +): UserSubscriptionsService => { const userUnsubscribeStore = new FakeUserUnsubscribeStore(); const eventService = createFakeEventsService(config); diff --git a/src/lib/services/index.ts b/src/lib/services/index.ts index a38f493ca5e0..3015a22f76c5 100644 --- a/src/lib/services/index.ts +++ b/src/lib/services/index.ts @@ -70,6 +70,7 @@ import { createFakeEnvironmentService, createFakeEventsService, createFakeProjectService, + createFakeUserSubscriptionsService, createFeatureLifecycleService, createFeatureToggleService, createProjectService, @@ -430,7 +431,7 @@ export const createServices = ( const transactionalUserSubscriptionsService = db ? withTransactional(createUserSubscriptionsService(config), db) - : withFakeTransactional(createUserSubscriptionsService(config)); + : withFakeTransactional(createFakeUserSubscriptionsService(config)); return { transactionalAccessService,