@@ -21,21 +21,20 @@ import { guid } from "../Utils.js";
21
21
import { KnownEventDataKeys } from "../models/Event.js" ;
22
22
23
23
export class Configuration {
24
- private handler = {
25
- set : ( target , key , value ) => {
26
- console . log ( key , ` set to ${ value } ` ) ;
27
- target [ key ] = value ;
28
- return true ;
29
- }
30
- } ;
31
-
32
24
constructor ( ) {
25
+ // TODO: Can we make this seamless via setters.
26
+ this . services = new Proxy ( {
27
+ lastReferenceIdManager : new DefaultLastReferenceIdManager ( ) ,
28
+ log : new NullLog ( ) ,
29
+ storage : new InMemoryStorageProvider ( ) ,
30
+ queue : new DefaultEventQueue ( this )
31
+ } , this . subscriberHandler ) ;
32
+
33
33
// TODO: Verify this works in derived classes.
34
- return new Proxy ( this , this . handler ) ;
34
+ return new Proxy ( this , this . subscriberHandler ) ;
35
35
}
36
36
37
37
// TODO: add flag if your suspended.
38
- // TODO: change version to be a string.
39
38
/**
40
39
* A default list of tags that will automatically be added to every
41
40
* report submitted to the server.
@@ -61,21 +60,16 @@ export class Configuration {
61
60
public enabled : boolean = true ;
62
61
63
62
public services : {
64
- environmentInfoCollector ?: IEnvironmentInfoCollector ,
65
- errorParser ?: IErrorParser ,
66
- lastReferenceIdManager : ILastReferenceIdManager ,
67
- log : ILog ,
68
- moduleCollector ?: IModuleCollector ,
69
- requestInfoCollector ?: IRequestInfoCollector ,
70
- submissionClient ?: ISubmissionClient ,
71
- storage : IStorageProvider ,
72
- queue : IEventQueue
73
- } = new Proxy ( {
74
- lastReferenceIdManager : new DefaultLastReferenceIdManager ( ) ,
75
- log : new NullLog ( ) ,
76
- storage : new InMemoryStorageProvider ( ) ,
77
- queue : new DefaultEventQueue ( this )
78
- } , this . handler ) ;
63
+ environmentInfoCollector ?: IEnvironmentInfoCollector ,
64
+ errorParser ?: IErrorParser ,
65
+ lastReferenceIdManager : ILastReferenceIdManager ,
66
+ log : ILog ,
67
+ moduleCollector ?: IModuleCollector ,
68
+ requestInfoCollector ?: IRequestInfoCollector ,
69
+ submissionClient ?: ISubmissionClient ,
70
+ storage : IStorageProvider ,
71
+ queue : IEventQueue
72
+ } ;
79
73
80
74
/**
81
75
* Maximum number of events that should be sent to the server together in a batch. (Defaults to 50)
@@ -174,7 +168,7 @@ export class Configuration {
174
168
public set apiKey ( value : string ) {
175
169
this . _apiKey = value || null ;
176
170
this . services . log . info ( `apiKey: ${ this . _apiKey } ` ) ;
177
- this . changed ( ) ;
171
+ this . notifySubscribers ( ) ;
178
172
}
179
173
180
174
/**
@@ -203,7 +197,7 @@ export class Configuration {
203
197
this . _configServerUrl = value ;
204
198
this . _heartbeatServerUrl = value ;
205
199
this . services . log . info ( `serverUrl: ${ value } ` ) ;
206
- this . changed ( ) ;
200
+ this . notifySubscribers ( ) ;
207
201
}
208
202
}
209
203
@@ -223,7 +217,7 @@ export class Configuration {
223
217
if ( value ) {
224
218
this . _configServerUrl = value ;
225
219
this . services . log . info ( `configServerUrl: ${ value } ` ) ;
226
- this . changed ( ) ;
220
+ this . notifySubscribers ( ) ;
227
221
}
228
222
}
229
223
@@ -243,7 +237,7 @@ export class Configuration {
243
237
if ( value ) {
244
238
this . _heartbeatServerUrl = value ;
245
239
this . services . log . info ( `heartbeatServerUrl: ${ value } ` ) ;
246
- this . changed ( ) ;
240
+ this . notifySubscribers ( ) ;
247
241
}
248
242
}
249
243
@@ -272,7 +266,7 @@ export class Configuration {
272
266
273
267
this . _updateSettingsWhenIdleInterval = value ;
274
268
this . services . log . info ( `updateSettingsWhenIdleInterval: ${ value } ` ) ;
275
- this . changed ( ) ;
269
+ this . notifySubscribers ( ) ;
276
270
}
277
271
278
272
/**
@@ -327,7 +321,7 @@ export class Configuration {
327
321
this . _includePostData = val ;
328
322
this . _includeQueryString = val ;
329
323
this . services . log . info ( `includePrivateInformation: ${ val } ` ) ;
330
- this . changed ( ) ;
324
+ this . notifySubscribers ( ) ;
331
325
}
332
326
333
327
/**
@@ -344,7 +338,7 @@ export class Configuration {
344
338
*/
345
339
public set includeUserName ( value : boolean ) {
346
340
this . _includeUserName = value === true ;
347
- this . changed ( ) ;
341
+ this . notifySubscribers ( ) ;
348
342
}
349
343
350
344
/**
@@ -361,7 +355,7 @@ export class Configuration {
361
355
*/
362
356
public set includeMachineName ( value : boolean ) {
363
357
this . _includeMachineName = value === true ;
364
- this . changed ( ) ;
358
+ this . notifySubscribers ( ) ;
365
359
}
366
360
367
361
/**
@@ -378,7 +372,7 @@ export class Configuration {
378
372
*/
379
373
public set includeIpAddress ( value : boolean ) {
380
374
this . _includeIpAddress = value === true ;
381
- this . changed ( ) ;
375
+ this . notifySubscribers ( ) ;
382
376
}
383
377
384
378
/**
@@ -397,7 +391,7 @@ export class Configuration {
397
391
*/
398
392
public set includeCookies ( value : boolean ) {
399
393
this . _includeCookies = value === true ;
400
- this . changed ( ) ;
394
+ this . notifySubscribers ( ) ;
401
395
}
402
396
403
397
/**
@@ -416,7 +410,7 @@ export class Configuration {
416
410
*/
417
411
public set includePostData ( value : boolean ) {
418
412
this . _includePostData = value === true ;
419
- this . changed ( ) ;
413
+ this . notifySubscribers ( ) ;
420
414
}
421
415
422
416
/**
@@ -435,7 +429,7 @@ export class Configuration {
435
429
*/
436
430
public set includeQueryString ( value : boolean ) {
437
431
this . _includeQueryString = value === true ;
438
- this . changed ( ) ;
432
+ this . notifySubscribers ( ) ;
439
433
}
440
434
441
435
/**
@@ -490,16 +484,8 @@ export class Configuration {
490
484
* @param priority Used to determine plugins priority.
491
485
* @param pluginAction A function that is run.
492
486
*/
493
- public addPlugin (
494
- name : string ,
495
- priority : number ,
496
- pluginAction : ( context : EventPluginContext ) => Promise < void > ,
497
- ) : void ;
498
- public addPlugin (
499
- pluginOrName : IEventPlugin | string ,
500
- priority ?: number ,
501
- pluginAction ?: ( context : EventPluginContext ) => Promise < void > ,
502
- ) : void {
487
+ public addPlugin ( name : string , priority : number , pluginAction : ( context : EventPluginContext ) => Promise < void > ) : void ;
488
+ public addPlugin ( pluginOrName : IEventPlugin | string , priority ?: number , pluginAction ?: ( context : EventPluginContext ) => Promise < void > ) : void {
503
489
const plugin : IEventPlugin = pluginAction
504
490
? { name : pluginOrName as string , priority, run : pluginAction }
505
491
: pluginOrName as IEventPlugin ;
@@ -559,12 +545,21 @@ export class Configuration {
559
545
}
560
546
561
547
/**
562
- * Automatically set the application version for events.
548
+ * The application version for events.
549
+ */
550
+ public get version ( ) : string {
551
+ return < string > this . defaultData [ KnownEventDataKeys . Version ] ;
552
+ }
553
+
554
+ /**
555
+ * Set the application version for events.
563
556
* @param version
564
557
*/
565
- public setVersion ( version : string ) : void {
558
+ public set version ( version : string ) {
566
559
if ( version ) {
567
560
this . defaultData [ KnownEventDataKeys . Version ] = version ;
561
+ } else {
562
+ delete this . defaultData [ KnownEventDataKeys . Version ] ;
568
563
}
569
564
}
570
565
@@ -587,9 +582,7 @@ export class Configuration {
587
582
this . defaultData [ KnownEventDataKeys . UserInfo ] = userInfo ;
588
583
}
589
584
590
- this . services . log . info (
591
- `user identity: ${ shouldRemove ? "null" : userInfo . identity } ` ,
592
- ) ;
585
+ this . services . log . info ( `user identity: ${ shouldRemove ? "null" : userInfo . identity } ` ) ;
593
586
}
594
587
595
588
/**
@@ -603,10 +596,7 @@ export class Configuration {
603
596
/**
604
597
* Automatically send a heartbeat to keep the session alive.
605
598
*/
606
- public useSessions (
607
- sendHeartbeats : boolean = true ,
608
- heartbeatInterval : number = 30000 ,
609
- ) : void {
599
+ public useSessions ( sendHeartbeats : boolean = true , heartbeatInterval : number = 30000 ) : void {
610
600
if ( sendHeartbeats ) {
611
601
this . addPlugin ( new HeartbeatPlugin ( heartbeatInterval ) ) ;
612
602
}
@@ -628,14 +618,24 @@ export class Configuration {
628
618
handler && this . _subscribers . push ( handler ) ;
629
619
}
630
620
631
- protected changed ( ) {
632
- const handlers = this . _subscribers ; // optimization for minifier.
633
- for ( const handler of handlers ) {
621
+ protected notifySubscribers ( ) {
622
+ for ( const handler of this . _subscribers ) {
634
623
try {
635
624
handler ( this ) ;
636
625
} catch ( ex ) {
637
626
this . services . log . error ( `Error calling subscribe handler: ${ ex } ` ) ;
638
627
}
639
628
}
640
629
}
630
+
631
+ // TODO: Rework handlers as it will set property values with the friendly key as well as private members.
632
+ private subscriberHandler = {
633
+ set : ( target , key : string | symbol , value : unknown ) : boolean => {
634
+ this . services . log . trace ( `${ typeof key === "symbol" ? key . toString ( ) : key } set to ${ value } ` ) ;
635
+ target [ key ] = value ;
636
+ this . notifySubscribers ( ) ;
637
+ return true ;
638
+ }
639
+ } ;
640
+
641
641
}
0 commit comments