diff --git a/src/services/notification/index.ts b/src/services/notification/index.ts index faf2ad6..e2f40aa 100644 --- a/src/services/notification/index.ts +++ b/src/services/notification/index.ts @@ -8,7 +8,10 @@ export type { } from './types.js'; export { BaseNotificationService } from './base-notification-service.js'; -export { NotificationFactory } from './notification-factory.js'; +export { + createNotificationService, + createNotificationServices, +} from './notification-factory.js'; export { NotificationManager, createNotificationManager } from './notification-manager.js'; export { FeishuNotificationService } from './providers/feishu-notification-service.js'; export { WeComNotificationService } from './providers/wecom-notification-service.js'; diff --git a/src/services/notification/notification-factory.ts b/src/services/notification/notification-factory.ts index 28aec62..cbde189 100644 --- a/src/services/notification/notification-factory.ts +++ b/src/services/notification/notification-factory.ts @@ -1,25 +1,20 @@ -import type { - INotificationService, - NotificationServiceConfig, -} from './types.js'; import { FeishuNotificationService } from './providers/feishu-notification-service.js'; import { WeComNotificationService } from './providers/wecom-notification-service.js'; +import type { INotificationService, NotificationServiceConfig } from './types.js'; -export class NotificationFactory { - static createService(config: NotificationServiceConfig): INotificationService { - switch (config.provider) { - case 'feishu': - return new FeishuNotificationService(config); - case 'wecom': - return new WeComNotificationService(config); - default: - throw new Error(`Unknown notification provider: ${config.provider}`); - } - } - - static createServices(configs: NotificationServiceConfig[]): INotificationService[] { - return configs - .filter((c) => c.enabled && c.webhookUrl) - .map((c) => this.createService(c)); +export function createNotificationService(config: NotificationServiceConfig): INotificationService { + switch (config.provider) { + case 'feishu': + return new FeishuNotificationService(config); + case 'wecom': + return new WeComNotificationService(config); + default: + throw new Error(`Unknown notification provider: ${config.provider}`); } } + +export function createNotificationServices( + configs: NotificationServiceConfig[] +): INotificationService[] { + return configs.filter((c) => c.enabled && c.webhookUrl).map((c) => createNotificationService(c)); +} diff --git a/src/services/notification/notification-manager.ts b/src/services/notification/notification-manager.ts index a10839d..73a232a 100644 --- a/src/services/notification/notification-manager.ts +++ b/src/services/notification/notification-manager.ts @@ -1,11 +1,11 @@ +import { logger } from '../../utils/logger.js'; +import { createNotificationServices } from './notification-factory.js'; import type { INotificationService, NotificationContext, NotificationMessage, NotificationProvider, } from './types.js'; -import { NotificationFactory } from './notification-factory.js'; -import { logger } from '../../utils/logger.js'; export class NotificationManager { private services: INotificationService[] = []; @@ -100,6 +100,6 @@ export class NotificationManager { export function createNotificationManager( configs: import('./types.js').NotificationServiceConfig[] ): NotificationManager { - const services = NotificationFactory.createServices(configs); + const services = createNotificationServices(configs); return new NotificationManager(services); }