22
33// TODO: We'll need a poly fill for promises.
44module Exceptionless {
5- class ExceptionlessClient {
6- private _config :Configuration ;
5+ export class ExceptionlessClient {
6+ public config :Configuration ;
77
88 constructor ( apiKey :string , serverUrl ?:string ) {
9- this . _config = new Configuration ( apiKey , serverUrl ) ;
10- }
11-
12- apply ( config :Configuration ) {
13- for ( var name in config || { } ) {
14- this . _config [ name ] = config [ name ] ;
15- }
9+ this . config = new Configuration ( apiKey , serverUrl ) ;
1610 }
1711
1812 submit ( events :ExceptionlessEvent ) {
19- if ( ! this . _config . enabled ) {
20- this . _config . log . info ( 'Event submission is currently disabled' ) ;
13+ if ( ! this . config . enabled ) {
14+ this . config . log . info ( 'Event submission is currently disabled' ) ;
2115 return ;
2216 }
2317 }
2418 }
2519
26- class Configuration {
20+ export class Configuration {
2721 apiKey :string ;
28- serverUrl = 'https://collector.exceptionless.io/api/v2' ;
22+ serverUrl : string ;
2923 enabled = true ;
3024
3125 log :ILog = new NullLog ( ) ;
@@ -35,34 +29,34 @@ module Exceptionless {
3529 queue :IEventQueue ;
3630
3731 constructor ( apiKey :string , serverUrl ?:string ) {
32+ this . setApiKey ( apiKey ) ;
33+ this . serverUrl = serverUrl || 'https://collector.exceptionless.io/api/v2' ;
34+ this . queue = new EventQueue ( this ) ;
35+ }
36+
37+ public setApiKey ( apiKey :string ) {
3838 this . apiKey = apiKey ;
3939 this . enabled = ! ! apiKey ;
40-
41- if ( ! ! serverUrl ) {
42- this . serverUrl = serverUrl ;
43- }
44-
45- this . queue = new EventQueue ( this ) ;
4640 }
4741
4842 public getQueueName ( ) : string {
4943 return ! ! this . apiKey ? 'ex-' + this . apiKey . slice ( 0 , 8 ) : null ;
5044 }
5145 }
5246
53- interface ILog {
47+ export interface ILog {
5448 info ( message :string ) ;
5549 warn ( message :string ) ;
5650 error ( message :string ) ;
5751 }
5852
59- class NullLog implements ILog {
53+ export class NullLog implements ILog {
6054 public info ( message ) { }
6155 public warn ( message ) { }
6256 public error ( message ) { }
6357 }
6458
65- class ConsoleLog implements ILog {
59+ export class ConsoleLog implements ILog {
6660 public info ( message ) {
6761 console . log ( '[INFO] Exceptionless:' + message )
6862 }
@@ -76,13 +70,13 @@ module Exceptionless {
7670 }
7771 }
7872
79- interface IEventQueue {
73+ export interface IEventQueue {
8074 enqueue ( event :ExceptionlessEvent ) ;
8175 process ( ) ;
8276 suspendProcessing ( durationInMinutes ?:number , discardFutureQueuedItems ?:boolean , clearQueue ?:boolean ) ;
8377 }
8478
85- class EventQueue implements IEventQueue {
79+ export class EventQueue implements IEventQueue {
8680 private _config :Configuration ;
8781 private _areQueuedItemsDiscarded = false ;
8882 private _suspendProcessingUntil :Date ;
@@ -218,13 +212,13 @@ module Exceptionless {
218212 }
219213 }
220214
221- interface ISubmissionClient {
215+ export interface ISubmissionClient {
222216 submitEvents ( events :ExceptionlessEvent [ ] , config :Configuration ) : Promise < SubmissionResponse > ;
223217 submitUserDescription ( referenceId :string , description :UserDescription , config :Configuration ) : Promise < SubmissionResponse > ;
224218 getSettings ( config :Configuration ) : Promise < SettingsResponse > ;
225219 }
226220
227- class SubmissionClient implements ISubmissionClient {
221+ export class SubmissionClient implements ISubmissionClient {
228222 public submitEvents ( events :ExceptionlessEvent [ ] , config :Configuration ) : Promise < SubmissionResponse > {
229223 var url = config . serverUrl + '/events?access_token=' + encodeURIComponent ( config . apiKey ) ;
230224 return this . sendRequest ( 'POST' , url , JSON . stringify ( events ) ) . then (
@@ -320,7 +314,7 @@ module Exceptionless {
320314 }
321315 }
322316
323- class SubmissionResponse {
317+ export class SubmissionResponse {
324318 success = false ;
325319 badRequest = false ;
326320 serviceUnavailable = false ;
@@ -345,7 +339,7 @@ module Exceptionless {
345339 }
346340 }
347341
348- class SettingsResponse {
342+ export class SettingsResponse {
349343 success = false ;
350344 settings :any ;
351345 settingsVersion = - 1 ;
@@ -361,13 +355,13 @@ module Exceptionless {
361355 }
362356 }
363357
364- interface IStorage < T > {
358+ export interface IStorage < T > {
365359 save < T > ( path :string , value :T ) : boolean ;
366360 get ( searchPattern ?:string , limit ?:number ) : T [ ] ;
367361 clear ( searchPattern ?:string ) ;
368362 }
369363
370- class InMemoryStorage < T > implements IStorage < T > {
364+ export class InMemoryStorage < T > implements IStorage < T > {
371365 public save < T > ( path :string , value :T ) : boolean {
372366 return false ;
373367 }
@@ -381,7 +375,7 @@ module Exceptionless {
381375 }
382376 }
383377
384- class ExceptionlessEvent { }
378+ export class ExceptionlessEvent { }
385379
386- class UserDescription { }
380+ export class UserDescription { }
387381}
0 commit comments