@@ -5,7 +5,6 @@ import { ConsoleLog } from "../logging/ConsoleLog.js";
5
5
import { NullLog } from "../logging/NullLog.js" ;
6
6
import { UserInfo } from "../models/data/UserInfo.js" ;
7
7
import { HeartbeatPlugin } from "../plugins/default/HeartbeatPlugin.js" ;
8
- import { ReferenceIdPlugin } from "../plugins/default/ReferenceIdPlugin.js" ;
9
8
import { EventPluginContext } from "../plugins/EventPluginContext.js" ;
10
9
import { IEventPlugin } from "../plugins/IEventPlugin.js" ;
11
10
import { DefaultEventQueue } from "../queue/DefaultEventQueue.js" ;
@@ -362,23 +361,14 @@ export class Configuration {
362
361
/**
363
362
* Register an plugin to be used in this configuration.
364
363
*/
365
- public addPlugin (
366
- name : string | undefined ,
367
- priority : number ,
368
- pluginAction : ( context : EventPluginContext ) => Promise < void > ,
369
- ) : void ;
370
- public addPlugin (
371
- pluginOrName : IEventPlugin | string | undefined ,
372
- priority ?: number ,
373
- pluginAction ?: ( context : EventPluginContext ) => Promise < void > ,
374
- ) : void {
364
+ public addPlugin ( name : string | undefined , priority : number , pluginAction : ( context : EventPluginContext ) => Promise < void > ) : void ;
365
+ public addPlugin ( pluginOrName : IEventPlugin | string | undefined , priority ?: number , pluginAction ?: ( context : EventPluginContext ) => Promise < void > ) : void {
375
366
const plugin : IEventPlugin = pluginAction
376
367
? { name : pluginOrName as string , priority, run : pluginAction }
377
368
: pluginOrName as IEventPlugin ;
369
+
378
370
if ( ! plugin || ! ( plugin . startup || plugin . run ) ) {
379
- this . services . log . error (
380
- "Add plugin failed: startup or run method not defined" ,
381
- ) ;
371
+ this . services . log . error ( "Add plugin failed: startup or run method not defined" ) ;
382
372
return ;
383
373
}
384
374
@@ -390,17 +380,8 @@ export class Configuration {
390
380
plugin . priority = 0 ;
391
381
}
392
382
393
- let pluginExists = false ;
394
- const plugins = this . _plugins ; // optimization for minifier.
395
- for ( const p of plugins ) {
396
- if ( p . name === plugin . name ) {
397
- pluginExists = true ;
398
- break ;
399
- }
400
- }
401
-
402
- if ( ! pluginExists ) {
403
- plugins . push ( plugin ) ;
383
+ if ( ! this . _plugins . find ( f => f . name === plugin . name ) ) {
384
+ this . _plugins . push ( plugin ) ;
404
385
}
405
386
}
406
387
@@ -443,26 +424,33 @@ export class Configuration {
443
424
}
444
425
}
445
426
446
- public setUserIdentity ( userInfo : UserInfo ) : void ;
447
- public setUserIdentity ( identity : string ) : void ;
448
- public setUserIdentity ( identity : string , name : string ) : void ;
449
- public setUserIdentity (
450
- userInfoOrIdentity : UserInfo | string ,
451
- name ?: string ,
452
- ) : void {
427
+ /**
428
+ * Set the default user identity for all events. If the heartbeat interval is
429
+ * greater than 0 (default: 30000ms), heartbeats will be sent after the first
430
+ * event submission.
431
+ */
432
+ public setUserIdentity ( userInfo : UserInfo , heartbeatInterval ?: number ) : void ;
433
+ public setUserIdentity ( identity : string , heartbeatInterval ?: number ) : void ;
434
+ public setUserIdentity ( identity : string , name : string , heartbeatInterval ?: number ) : void ;
435
+ public setUserIdentity ( userInfoOrIdentity : UserInfo | string , nameOrHeartbeatInterval ?: string | number , heartbeatInterval : number = 30000 ) : void {
436
+ const name : string | undefined = typeof nameOrHeartbeatInterval === "string" ? nameOrHeartbeatInterval : undefined ;
453
437
const userInfo : UserInfo = typeof userInfoOrIdentity !== "string"
454
438
? userInfoOrIdentity
455
439
: { identity : userInfoOrIdentity , name } ;
456
440
457
- const shouldRemove : boolean = ! userInfo ||
458
- ( ! userInfo . identity && ! userInfo . name ) ;
441
+ const interval : number = typeof nameOrHeartbeatInterval === "number" ? nameOrHeartbeatInterval : heartbeatInterval ;
442
+ const plugin = new HeartbeatPlugin ( interval ) ;
443
+
444
+ const shouldRemove : boolean = ! userInfo || ( ! userInfo . identity && ! userInfo . name ) ;
459
445
if ( shouldRemove ) {
446
+ this . removePlugin ( plugin )
460
447
delete this . defaultData [ KnownEventDataKeys . UserInfo ] ;
461
448
} else {
449
+ this . addPlugin ( plugin )
462
450
this . defaultData [ KnownEventDataKeys . UserInfo ] = userInfo ;
463
451
}
464
452
465
- this . services . log . info ( `user identity: ${ shouldRemove ? "null" : < string > userInfo . identity } ` ) ;
453
+ this . services . log . info ( `user identity: ${ shouldRemove ? "null" : < string > userInfo . identity } (heartbeat interval: ${ interval } ms) ` ) ;
466
454
}
467
455
468
456
/**
@@ -472,15 +460,6 @@ export class Configuration {
472
460
return "exceptionless-js/2.0.0-dev" ;
473
461
}
474
462
475
- /**
476
- * Automatically send a heartbeat to keep the session alive.
477
- */
478
- public useSessions ( sendHeartbeats = true , heartbeatInterval = 30000 ) : void {
479
- if ( sendHeartbeats ) {
480
- this . addPlugin ( new HeartbeatPlugin ( heartbeatInterval ) ) ;
481
- }
482
- }
483
-
484
463
/**
485
464
* Use localStorage for persisting things like server configuration cache and persisted queue entries (depends on usePersistedQueueStorage).
486
465
*/
0 commit comments