Skip to content

Commit 8a6ed55

Browse files
committed
[WIP] Added the ability to pull server side changes.
We now also set a user agent and have data exclusions (WIP). Added some documentation (from the .NET client)
1 parent cf5ed14 commit 8a6ed55

20 files changed

+326
-91
lines changed

src/EventBuilder.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { EventPluginContext } from './plugins/EventPluginContext';
77
import { Utils } from 'Utils';
88

99
export class EventBuilder {
10+
private _validIdentifierErrorMessage:string = "must contain between 8 and 100 alphanumeric or '-' characters.";
11+
1012
public target:IEvent;
1113
public client:ExceptionlessClient;
1214
public pluginContextData:ContextData;
@@ -35,7 +37,7 @@ export class EventBuilder {
3537

3638
public setSessionId(sessionId:string): EventBuilder {
3739
if (!this.isValidIdentifier(sessionId)) {
38-
throw new Error("SessionId must contain between 8 and 100 alphanumeric or '-' characters.");
40+
throw new Error(`SessionId ${this._validIdentifierErrorMessage}`);
3941
}
4042

4143
this.target.session_id = sessionId;
@@ -44,7 +46,7 @@ export class EventBuilder {
4446

4547
public setReferenceId(referenceId:string): EventBuilder {
4648
if (!this.isValidIdentifier(referenceId)) {
47-
throw new Error("SessionId must contain between 8 and 100 alphanumeric or '-' characters.");
49+
throw new Error(`ReferenceId ${this._validIdentifierErrorMessage}`);
4850
}
4951

5052
this.target.reference_id = referenceId;
@@ -82,8 +84,6 @@ export class EventBuilder {
8284
return this;
8385
}
8486

85-
// TODO: we to see if it makes sense to add setUserDescription.
86-
8787
public setValue(value:number): EventBuilder {
8888
if (!!value) {
8989
this.target.value = value;
@@ -93,20 +93,7 @@ export class EventBuilder {
9393
}
9494

9595
public addTags(...tags:string[]): EventBuilder {
96-
if (!tags || tags.length === 0) {
97-
return this;
98-
}
99-
100-
if (!this.target.tags) {
101-
this.target.tags = [];
102-
}
103-
104-
for (var index = 0; index < tags.length; index++) {
105-
if (tags[index] && this.target.tags.indexOf(tags[index]) < 0) {
106-
this.target.tags.push(tags[index]);
107-
}
108-
}
109-
96+
this.target.tags = Utils.addRange<string>(this.target.tags, ...tags);
11097
return this;
11198
}
11299

@@ -131,7 +118,8 @@ export class EventBuilder {
131118
return this;
132119
}
133120

134-
public addRequestInfo(request:any): EventBuilder {
121+
//todo: rename this
122+
public addRequestInfo(request:Object): EventBuilder {
135123
if (!!request) {
136124
this.pluginContextData['@request'] = request;
137125
}

src/Utils-spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
import { IEvent } from './models/IEvent';
12
import { Utils } from 'Utils';
23

34
describe('Utils', () => {
5+
it('should add range', () => {
6+
var target:string[];
7+
expect(Utils.addRange(target)).toEqual([]);
8+
expect(target).toBeUndefined();
9+
10+
expect(Utils.addRange(target, '1', '2')).toEqual(['1', '2']);
11+
expect(Utils.addRange(target, '1', '2')).toEqual(['1', '2']);
12+
13+
target = ['3'];
14+
expect(Utils.addRange(target, '1', '2')).toEqual(['3', '1', '2']);
15+
expect(target).toEqual(['3', '1', '2']);
16+
});
17+
418
it('should stringify circular reference', () => {
519
var afoo:any = {a: 'foo'};
620
afoo.b = afoo;
@@ -10,7 +24,7 @@ describe('Utils', () => {
1024
});
1125

1226
it('should stringify array', () => {
13-
var error = {
27+
var error:IEvent = {
1428
"type": "error",
1529
"data": {
1630
"@error": {

src/Utils.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { IStackFrame } from 'models/IStackFrame';
22

33
export class Utils {
4+
public static addRange<T>(target:T[], ...values:T[]) {
5+
if (!target) {
6+
target = [];
7+
}
8+
9+
if (!values || values.length === 0) {
10+
return target;
11+
}
12+
13+
for (var index = 0; index < values.length; index++) {
14+
if (values[index] && target.indexOf(values[index]) < 0) {
15+
target.push(values[index]);
16+
}
17+
}
18+
19+
return target;
20+
}
21+
422
public static getHashCode(source:string): string {
523
if (!source || source.length === 0) {
624
return null;
@@ -17,11 +35,11 @@ export class Utils {
1735
}
1836

1937
public static getCookies(cookies:string): Object {
20-
var result = {};
38+
var result:Object = {};
2139

22-
var parts = (cookies || '').split('; ');
40+
var parts:string[] = (cookies || '').split('; ');
2341
for (var index = 0; index < parts.length; index++) {
24-
var cookie = parts[index].split('=');
42+
var cookie:string[] = parts[index].split('=');
2543
result[cookie[0]] = cookie[1];
2644
}
2745

@@ -36,8 +54,8 @@ export class Utils {
3654
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
3755
}
3856

39-
public static merge(defaultValues:any, values:any) {
40-
var result = {};
57+
public static merge(defaultValues:Object, values:Object) {
58+
var result:Object = {};
4159

4260
for (var key in defaultValues || {}) {
4361
if (!!defaultValues[key]) {
@@ -78,7 +96,7 @@ export class Utils {
7896
return null;
7997
}
8098

81-
var result = {};
99+
var result:Object = {};
82100
for (var index = 0; index < pairs.length; index++) {
83101
var pair = pairs[index].split('=');
84102
result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
@@ -93,7 +111,7 @@ export class Utils {
93111

94112
public static stringify(data:any): string {
95113
function stringifyImpl(data:any): string {
96-
var cache = [];
114+
var cache:string[] = [];
97115
return JSON.stringify(data, function(key:string, value:any) {
98116
if (typeof value === 'object' && !!value) {
99117
if (cache.indexOf(value) !== -1) {

src/bootstrap/NodeBootstrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class NodeBootstrapper implements IBootstrapper {
2121
configDefaults.requestInfoCollector = new NodeRequestInfoCollector();
2222
configDefaults.submissionClient = new NodeSubmissionClient();
2323

24-
process.on('uncaughtException', function(error) {
24+
process.on('uncaughtException', function(error:Error) {
2525
ExceptionlessClient.default.submitUnhandledException(error, 'uncaughtException');
2626
});
2727

src/bootstrap/WindowBootstrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export class WindowBootstrapper implements IBootstrapper {
4949
return null;
5050
}
5151

52-
private processUnhandledException(stackTrace:TraceKit.StackTrace, options): void {
52+
private processUnhandledException(stackTrace:TraceKit.StackTrace, options?:any): void {
5353
var builder = ExceptionlessClient.default.createUnhandledException(new Error(stackTrace.message || (options || {}).status || 'Script error'), 'onerror');
5454
builder.pluginContextData['@@_TraceKit.StackTrace'] = stackTrace;
5555
builder.submit();
5656
}
5757

58-
private processJQueryAjaxError(event, xhr, settings, error): void {
58+
private processJQueryAjaxError(event, xhr, settings, error:Error): void {
5959
var client = ExceptionlessClient.default;
6060
if (xhr.status === 404) {
6161
client.submitNotFound(settings.url);

0 commit comments

Comments
 (0)