1
+ import type EventEmitter from 'events' ;
1
2
import { APPLICATION_CREATED , CLIENT_REGISTER } from '../../../types/events' ;
2
3
import type { IApplication , IApplicationOverview } from './models' ;
3
4
import type { IUnleashStores } from '../../../types/stores' ;
@@ -24,6 +25,7 @@ import { ALL_PROJECTS, parseStrictSemVer } from '../../../util';
24
25
import type { Logger } from '../../../logger' ;
25
26
import { findOutdatedSDKs , isOutdatedSdk } from './findOutdatedSdks' ;
26
27
import type { OutdatedSdksSchema } from '../../../openapi/spec/outdated-sdks-schema' ;
28
+ import { CLIENT_REGISTERED } from '../../../metric-events' ;
27
29
28
30
export default class ClientInstanceService {
29
31
apps = { } ;
@@ -48,6 +50,8 @@ export default class ClientInstanceService {
48
50
49
51
private flagResolver : IFlagResolver ;
50
52
53
+ private eventBus : EventEmitter ;
54
+
51
55
constructor (
52
56
{
53
57
clientMetricsStoreV2,
@@ -68,7 +72,8 @@ export default class ClientInstanceService {
68
72
{
69
73
getLogger,
70
74
flagResolver,
71
- } : Pick < IUnleashConfig , 'getLogger' | 'flagResolver' > ,
75
+ eventBus,
76
+ } : Pick < IUnleashConfig , 'getLogger' | 'flagResolver' | 'eventBus' > ,
72
77
privateProjectChecker : IPrivateProjectChecker ,
73
78
) {
74
79
this . clientMetricsStoreV2 = clientMetricsStoreV2 ;
@@ -77,6 +82,7 @@ export default class ClientInstanceService {
77
82
this . clientApplicationsStore = clientApplicationsStore ;
78
83
this . clientInstanceStore = clientInstanceStore ;
79
84
this . eventStore = eventStore ;
85
+ this . eventBus = eventBus ;
80
86
this . privateProjectChecker = privateProjectChecker ;
81
87
this . flagResolver = flagResolver ;
82
88
this . logger = getLogger (
@@ -105,6 +111,7 @@ export default class ClientInstanceService {
105
111
value . clientIp = clientIp ;
106
112
value . createdBy = SYSTEM_USER . username ! ;
107
113
this . seenClients [ this . clientKey ( value ) ] = value ;
114
+ this . eventBus . emit ( CLIENT_REGISTERED , value ) ;
108
115
109
116
if ( value . sdkVersion && value . sdkVersion . indexOf ( ':' ) > - 1 ) {
110
117
const [ sdkName , sdkVersion ] = value . sdkVersion . split ( ':' ) ;
0 commit comments