11import type { NotificationProvider } from "./providers/base" ;
2- import type { DiscordProviderConfig } from "./providers/discord" ;
3- import { DiscordProvider } from "./providers/discord" ;
42import type { EmailProviderConfig } from "./providers/email" ;
53import { EmailProvider } from "./providers/email" ;
6- import type { GoogleChatProviderConfig } from "./providers/google-chat" ;
7- import { GoogleChatProvider } from "./providers/google-chat" ;
84import type { SlackProviderConfig } from "./providers/slack" ;
95import { SlackProvider } from "./providers/slack" ;
10- import type { TeamsProviderConfig } from "./providers/teams" ;
11- import { TeamsProvider } from "./providers/teams" ;
12- import type { TelegramProviderConfig } from "./providers/telegram" ;
13- import { TelegramProvider } from "./providers/telegram" ;
146import type { WebhookProviderConfig } from "./providers/webhook" ;
157import { WebhookProvider } from "./providers/webhook" ;
168import type {
@@ -25,12 +17,8 @@ export interface NotificationClientConfig {
2517 defaultRetries ?: number ;
2618 defaultRetryDelay ?: number ;
2719 defaultTimeout ?: number ;
28- discord ?: DiscordProviderConfig ;
2920 email ?: EmailProviderConfig ;
30- googleChat ?: GoogleChatProviderConfig ;
3121 slack ?: SlackProviderConfig ;
32- teams ?: TeamsProviderConfig ;
33- telegram ?: TelegramProviderConfig ;
3422 webhook ?: WebhookProviderConfig ;
3523}
3624
@@ -48,87 +36,33 @@ export class NotificationClient {
4836 retryDelay : config . defaultRetryDelay ?? 1000 ,
4937 } ;
5038
39+ const withDefaults = <
40+ T extends { timeout ?: number ; retries ?: number ; retryDelay ?: number } ,
41+ > (
42+ c : T
43+ ) => ( {
44+ ...c ,
45+ timeout : c . timeout ?? defaults . timeout ,
46+ retries : c . retries ?? defaults . retries ,
47+ retryDelay : c . retryDelay ?? defaults . retryDelay ,
48+ } ) ;
49+
5150 if ( config . slack ) {
5251 this . providers . set (
5352 "slack" ,
54- new SlackProvider ( {
55- ...config . slack ,
56- timeout : config . slack . timeout ?? defaults . timeout ,
57- retries : config . slack . retries ?? defaults . retries ,
58- retryDelay : config . slack . retryDelay ?? defaults . retryDelay ,
59- } )
60- ) ;
61- }
62-
63- if ( config . discord ) {
64- this . providers . set (
65- "discord" ,
66- new DiscordProvider ( {
67- ...config . discord ,
68- timeout : config . discord . timeout ?? defaults . timeout ,
69- retries : config . discord . retries ?? defaults . retries ,
70- retryDelay : config . discord . retryDelay ?? defaults . retryDelay ,
71- } )
53+ new SlackProvider ( withDefaults ( config . slack ) )
7254 ) ;
7355 }
74-
7556 if ( config . email ) {
7657 this . providers . set (
7758 "email" ,
78- new EmailProvider ( {
79- ...config . email ,
80- timeout : config . email . timeout ?? defaults . timeout ,
81- retries : config . email . retries ?? defaults . retries ,
82- retryDelay : config . email . retryDelay ?? defaults . retryDelay ,
83- } )
59+ new EmailProvider ( withDefaults ( config . email ) )
8460 ) ;
8561 }
86-
8762 if ( config . webhook ) {
8863 this . providers . set (
8964 "webhook" ,
90- new WebhookProvider ( {
91- ...config . webhook ,
92- timeout : config . webhook . timeout ?? defaults . timeout ,
93- retries : config . webhook . retries ?? defaults . retries ,
94- retryDelay : config . webhook . retryDelay ?? defaults . retryDelay ,
95- } )
96- ) ;
97- }
98-
99- if ( config . teams ) {
100- this . providers . set (
101- "teams" ,
102- new TeamsProvider ( {
103- ...config . teams ,
104- timeout : config . teams . timeout ?? defaults . timeout ,
105- retries : config . teams . retries ?? defaults . retries ,
106- retryDelay : config . teams . retryDelay ?? defaults . retryDelay ,
107- } )
108- ) ;
109- }
110-
111- if ( config . telegram ) {
112- this . providers . set (
113- "telegram" ,
114- new TelegramProvider ( {
115- ...config . telegram ,
116- timeout : config . telegram . timeout ?? defaults . timeout ,
117- retries : config . telegram . retries ?? defaults . retries ,
118- retryDelay : config . telegram . retryDelay ?? defaults . retryDelay ,
119- } )
120- ) ;
121- }
122-
123- if ( config . googleChat ) {
124- this . providers . set (
125- "google-chat" ,
126- new GoogleChatProvider ( {
127- ...config . googleChat ,
128- timeout : config . googleChat . timeout ?? defaults . timeout ,
129- retries : config . googleChat . retries ?? defaults . retries ,
130- retryDelay : config . googleChat . retryDelay ?? defaults . retryDelay ,
131- } )
65+ new WebhookProvider ( withDefaults ( config . webhook ) )
13266 ) ;
13367 }
13468 }
0 commit comments