1
- import { ExceptionlessClient } from ' ./ExceptionlessClient.js' ;
2
- import { IEvent } from ' ./models/IEvent .js' ;
3
- import { IManualStackingInfo } from ' ./models/IManualStackingInfo .js' ;
4
- import { IRequestInfo } from "./models/IRequestInfo .js" ;
5
- import { IUserInfo } from ' ./models/IUserInfo .js' ;
6
- import { ContextData } from ' ./plugins/ContextData.js' ;
7
- import { EventPluginContext } from ' ./plugins/EventPluginContext.js' ;
8
- import { addRange , stringify , isEmpty } from "./Utils.js" ;
1
+ import { ExceptionlessClient } from " ./ExceptionlessClient.js" ;
2
+ import { Event } from " ./models/Event .js" ;
3
+ import { ManualStackingInfo } from " ./models/data/ManualStackingInfo .js" ;
4
+ import { RequestInfo } from "./models/data/RequestInfo .js" ;
5
+ import { UserInfo } from " ./models/data/UserInfo .js" ;
6
+ import { ContextData } from " ./plugins/ContextData.js" ;
7
+ import { EventPluginContext } from " ./plugins/EventPluginContext.js" ;
8
+ import { addRange , isEmpty , stringify } from "./Utils.js" ;
9
9
10
10
export class EventBuilder {
11
- public target : IEvent ;
11
+ public target : Event ;
12
12
public client : ExceptionlessClient ;
13
13
public pluginContextData : ContextData ;
14
14
15
- private _validIdentifierErrorMessage : string = 'must contain between 8 and 100 alphanumeric or \'-\' characters.' ; // optimization for minifier.
15
+ private _validIdentifierErrorMessage : string =
16
+ "must contain between 8 and 100 alphanumeric or '-' characters." ; // optimization for minifier.
16
17
17
- constructor ( event : IEvent , client : ExceptionlessClient , pluginContextData ?: ContextData ) {
18
+ constructor (
19
+ event : Event ,
20
+ client : ExceptionlessClient ,
21
+ pluginContextData ?: ContextData ,
22
+ ) {
18
23
this . target = event ;
19
24
this . client = client ;
20
25
this . pluginContextData = pluginContextData || new ContextData ( ) ;
@@ -53,14 +58,14 @@ export class EventBuilder {
53
58
*/
54
59
public setEventReference ( name : string , id : string ) : EventBuilder {
55
60
if ( ! name ) {
56
- throw new Error ( ' Invalid name' ) ;
61
+ throw new Error ( " Invalid name" ) ;
57
62
}
58
63
59
64
if ( ! id || ! this . isValidIdentifier ( id ) ) {
60
65
throw new Error ( `Id ${ this . _validIdentifierErrorMessage } ` ) ;
61
66
}
62
67
63
- this . setProperty ( ' @ref:' + name , id ) ;
68
+ this . setProperty ( " @ref:" + name , id ) ;
64
69
return this ;
65
70
}
66
71
@@ -74,27 +79,34 @@ export class EventBuilder {
74
79
75
80
public setGeo ( latitude : number , longitude : number ) : EventBuilder {
76
81
if ( latitude < - 90.0 || latitude > 90.0 ) {
77
- throw new Error ( ' Must be a valid latitude value between -90.0 and 90.0.' ) ;
82
+ throw new Error ( " Must be a valid latitude value between -90.0 and 90.0." ) ;
78
83
}
79
84
80
85
if ( longitude < - 180.0 || longitude > 180.0 ) {
81
- throw new Error ( 'Must be a valid longitude value between -180.0 and 180.0.' ) ;
86
+ throw new Error (
87
+ "Must be a valid longitude value between -180.0 and 180.0." ,
88
+ ) ;
82
89
}
83
90
84
91
this . target . geo = `${ latitude } ,${ longitude } ` ;
85
92
return this ;
86
93
}
87
94
88
- public setUserIdentity ( userInfo : IUserInfo ) : EventBuilder ;
95
+ public setUserIdentity ( userInfo : UserInfo ) : EventBuilder ;
89
96
public setUserIdentity ( identity : string ) : EventBuilder ;
90
97
public setUserIdentity ( identity : string , name : string ) : EventBuilder ;
91
- public setUserIdentity ( userInfoOrIdentity : IUserInfo | string , name ?: string ) : EventBuilder {
92
- const userInfo = typeof userInfoOrIdentity !== 'string' ? userInfoOrIdentity : { identity : userInfoOrIdentity , name } ;
98
+ public setUserIdentity (
99
+ userInfoOrIdentity : UserInfo | string ,
100
+ name ?: string ,
101
+ ) : EventBuilder {
102
+ const userInfo = typeof userInfoOrIdentity !== "string"
103
+ ? userInfoOrIdentity
104
+ : { identity : userInfoOrIdentity , name } ;
93
105
if ( ! userInfo || ( ! userInfo . identity && ! userInfo . name ) ) {
94
106
return this ;
95
107
}
96
108
97
- this . setProperty ( ' @user' , userInfo ) ;
109
+ this . setProperty ( " @user" , userInfo ) ;
98
110
return this ;
99
111
}
100
112
@@ -105,9 +117,15 @@ export class EventBuilder {
105
117
* @param description The user's description of the event.
106
118
* @returns {EventBuilder }
107
119
*/
108
- public setUserDescription ( emailAddress : string , description : string ) : EventBuilder {
120
+ public setUserDescription (
121
+ emailAddress : string ,
122
+ description : string ,
123
+ ) : EventBuilder {
109
124
if ( emailAddress && description ) {
110
- this . setProperty ( '@user_description' , { email_address : emailAddress , description } ) ;
125
+ this . setProperty ( "@user_description" , {
126
+ email_address : emailAddress ,
127
+ description,
128
+ } ) ;
111
129
}
112
130
113
131
return this ;
@@ -120,14 +138,17 @@ export class EventBuilder {
120
138
* @param title An optional title for the stacking information.
121
139
* @returns {EventBuilder }
122
140
*/
123
- public setManualStackingInfo ( signatureData : any , title ?: string ) : EventBuilder {
141
+ public setManualStackingInfo (
142
+ signatureData : any ,
143
+ title ?: string ,
144
+ ) : EventBuilder {
124
145
if ( signatureData ) {
125
- const stack : IManualStackingInfo = { signature_data : signatureData } ;
146
+ const stack : ManualStackingInfo = { signature_data : signatureData } ;
126
147
if ( title ) {
127
148
stack . title = title ;
128
149
}
129
150
130
- this . setProperty ( ' @stack' , stack ) ;
151
+ this . setProperty ( " @stack" , stack ) ;
131
152
}
132
153
133
154
return this ;
@@ -139,7 +160,10 @@ export class EventBuilder {
139
160
* @param title An optional title for the stacking information.
140
161
* @returns {EventBuilder }
141
162
*/
142
- public setManualStackingKey ( manualStackingKey : string , title ?: string ) : EventBuilder {
163
+ public setManualStackingKey (
164
+ manualStackingKey : string ,
165
+ title ?: string ,
166
+ ) : EventBuilder {
143
167
if ( manualStackingKey ) {
144
168
const data = { ManualStackingKey : manualStackingKey } ;
145
169
this . setManualStackingInfo ( data , title ) ;
@@ -174,7 +198,12 @@ export class EventBuilder {
174
198
* @param maxDepth The max depth of the object to include.
175
199
* @param excludedPropertyNames Any property names that should be excluded.
176
200
*/
177
- public setProperty ( name : string , value : any , maxDepth ?: number , excludedPropertyNames ?: string [ ] ) : EventBuilder {
201
+ public setProperty (
202
+ name : string ,
203
+ value : any ,
204
+ maxDepth ?: number ,
205
+ excludedPropertyNames ?: string [ ] ,
206
+ ) : EventBuilder {
178
207
if ( ! name || ( value === undefined || value == null ) ) {
179
208
return this ;
180
209
}
@@ -183,7 +212,13 @@ export class EventBuilder {
183
212
this . target . data = { } ;
184
213
}
185
214
186
- const result = JSON . parse ( stringify ( value , this . client . config . dataExclusions . concat ( excludedPropertyNames || [ ] ) , maxDepth ) ) ;
215
+ const result = JSON . parse (
216
+ stringify (
217
+ value ,
218
+ this . client . config . dataExclusions . concat ( excludedPropertyNames || [ ] ) ,
219
+ maxDepth ,
220
+ ) ,
221
+ ) ;
187
222
if ( ! isEmpty ( result ) ) {
188
223
this . target . data [ name ] = result ;
189
224
}
@@ -193,15 +228,15 @@ export class EventBuilder {
193
228
194
229
public markAsCritical ( critical : boolean ) : EventBuilder {
195
230
if ( critical ) {
196
- this . addTags ( ' Critical' ) ;
231
+ this . addTags ( " Critical" ) ;
197
232
}
198
233
199
234
return this ;
200
235
}
201
236
202
- public addRequestInfo ( request : IRequestInfo ) : EventBuilder {
237
+ public addRequestInfo ( request : RequestInfo ) : EventBuilder {
203
238
if ( request ) {
204
- this . pluginContextData [ ' @request' ] = request ;
239
+ this . pluginContextData [ " @request" ] = request ;
205
240
}
206
241
207
242
return this ;
@@ -223,7 +258,8 @@ export class EventBuilder {
223
258
for ( let index = 0 ; index < value . length ; index ++ ) {
224
259
const code = value . charCodeAt ( index ) ;
225
260
const isDigit = ( code >= 48 ) && ( code <= 57 ) ;
226
- const isLetter = ( ( code >= 65 ) && ( code <= 90 ) ) || ( ( code >= 97 ) && ( code <= 122 ) ) ;
261
+ const isLetter = ( ( code >= 65 ) && ( code <= 90 ) ) ||
262
+ ( ( code >= 97 ) && ( code <= 122 ) ) ;
227
263
const isMinus = code === 45 ;
228
264
229
265
if ( ! ( isDigit || isLetter ) && ! isMinus ) {
0 commit comments