Skip to content

Commit 21c7cfd

Browse files
committed
Huge refactor.
1 parent 97de0d7 commit 21c7cfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1936
-1723
lines changed

.gitignore

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1+
.DS_Store
2+
.idea
13
node_modules
2-
bower_components
34
public
4-
.DS_Store
5-
/.idea
6-
/src/.idea
7-
8-
src/exceptionless.js.map
9-
src/exceptionless.js
10-
src/exceptionless-spec.js
11-
src/exceptionless-spec.js.map
12-
/src/dist
13-
/src/typings
14-
/typings
5+
typings

gulpfile.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ var rename = require('gulp-rename');
66
var rimraf = require('rimraf');
77
var sourcemaps = require('gulp-sourcemaps');
88
var ts = require('gulp-typescript');
9+
var tsProject = require('tsproject');
910
var uglify = require('gulp-uglify');
1011

11-
var tsProject = ts.createProject({
12-
declarationFiles: true,
13-
module: 'AMD',
14-
removeComments: true,
15-
sortOutput: true,
16-
sourceMap: true,
17-
target: 'ES5'
18-
});
19-
2012
gulp.task('clean', function (cb) {
2113
rimraf('./dist', cb);
2214
});
2315

2416
gulp.task('scripts', function() {
17+
function fixFilePath(files){
18+
for (var index = 0; index < files.length; index++) {
19+
files[index] = 'src/' + files[index];
20+
}
21+
22+
return files;
23+
}
24+
2525
var files = [
2626
'node_modules/es6-promise/dist/es6-promise.js',
2727
'node_modules/stackframe/dist/stackframe.js',
@@ -31,7 +31,13 @@ gulp.task('scripts', function() {
3131
'node_modules/stacktrace-js/dist/stacktrace.js'
3232
];
3333

34-
var tsResult = gulp.src(['src/exceptionless.ts']).pipe(ts(tsProject));
34+
var tsconfig = require('./src/tsconfig.json');
35+
var tsResult = gulp.src(fixFilePath(tsconfig.files))
36+
.pipe(ts(tsconfig.compilerOptions));
37+
38+
//var tsResult = tsProject.src('./src');
39+
40+
// TODO: Look into using https://www.npmjs.com/package/gulp-wrap-umd
3541
return merge2(
3642
tsResult.dts.pipe(gulp.dest('dist')),
3743
merge2(gulp.src(files), tsResult.js)
@@ -52,7 +58,7 @@ gulp.task('watch', ['scripts'], function() {
5258
gulp.task('build', ['clean', 'scripts']);
5359

5460
gulp.task('test', [], function() {
55-
return gulp.src(['src/*-spec.ts'])
61+
return gulp.src(['src/**/*-spec.ts'])
5662
.pipe(karma({
5763
configFile: 'karma.conf.js',
5864
action: 'run'

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = function (config) {
1616
'node_modules/stacktrace-gps/dist/stacktrace-gps.js',
1717
'node_modules/stacktrace-js/dist/stacktrace.js',
1818

19-
'src/*.ts'
19+
'src/**/*.ts'
2020
],
2121
exclude: [],
2222
preprocessors: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"stackframe": "^0.2.2",
4444
"stacktrace-gps": "^2.1.2",
4545
"stacktrace-js": "git://github.com/stacktracejs/stacktrace.js.git",
46+
"tsproject": "^0.5.7",
4647
"typescript": "1.5.0-alpha"
4748
},
4849
"dependencies": {}

src/EventBuilder.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/// <reference path="references.ts" />
2+
3+
module Exceptionless {
4+
export class EventBuilder {
5+
public target:IEvent;
6+
public client:ExceptionlessClient;
7+
public pluginContextData:ContextData;
8+
9+
constructor(event:IEvent, client:ExceptionlessClient, pluginContextData?:ContextData) {
10+
this.target = event;
11+
this.client = client;
12+
this.pluginContextData = pluginContextData;
13+
}
14+
15+
public setType(type:string): EventBuilder {
16+
if (!!type && type.length > 0) {
17+
this.target.type = type;
18+
}
19+
20+
return this;
21+
}
22+
23+
public setSource(source:string): EventBuilder {
24+
if (!!source && source.length > 0) {
25+
this.target.source = source;
26+
}
27+
28+
return this;
29+
}
30+
31+
public setSessionId(sessionId:string): EventBuilder {
32+
if (!this.isValidIdentifier(sessionId)) {
33+
throw new Error("SessionId must contain between 8 and 100 alphanumeric or '-' characters.");
34+
}
35+
36+
this.target.session_id = sessionId;
37+
return this;
38+
}
39+
40+
public setReferenceId(referenceId:string): EventBuilder {
41+
if (!this.isValidIdentifier(referenceId)) {
42+
throw new Error("SessionId must contain between 8 and 100 alphanumeric or '-' characters.");
43+
}
44+
45+
this.target.reference_id = referenceId;
46+
return this;
47+
}
48+
49+
public setMessage(message:string): EventBuilder {
50+
if (!!message && message.length > 0) {
51+
this.target.message = message;
52+
}
53+
54+
return this;
55+
}
56+
57+
public setGeo(latitude: number, longitude: number): EventBuilder {
58+
if (latitude < -90.0 || latitude > 90.0)
59+
throw new Error('Must be a valid latitude value between -90.0 and 90.0.');
60+
if (longitude < -180.0 || longitude > 180.0)
61+
throw new Error('Must be a valid longitude value between -180.0 and 180.0.');
62+
63+
this.target.geo = latitude + ',' + longitude;
64+
return this;
65+
}
66+
67+
public setValue(value:number): EventBuilder {
68+
if (!!value) {
69+
this.target.value = value;
70+
}
71+
72+
return this;
73+
}
74+
75+
public addTags(...tags:string[]): EventBuilder {
76+
if (!tags || tags.length === 0) {
77+
return this;
78+
}
79+
80+
if (!this.target.tags) {
81+
this.target.tags = [];
82+
}
83+
84+
for (var index = 0; index < tags.length; index++) {
85+
if (tags[index] && this.target.tags.indexOf(tags[index]) < 0) {
86+
this.target.tags.push(tags[index]);
87+
}
88+
}
89+
90+
return this;
91+
}
92+
93+
public setProperty(name:string, value:any): EventBuilder {
94+
if (!name || (value === undefined || value == null)) {
95+
return this;
96+
}
97+
98+
if (!this.target.data) {
99+
this.target.data = {};
100+
}
101+
102+
this.target.data[name] = value;
103+
return this;
104+
}
105+
106+
public markAsCritical(critical:boolean): EventBuilder {
107+
if (critical) {
108+
this.addTags('Critical');
109+
}
110+
111+
return this;
112+
}
113+
114+
public submit(): Promise<any> {
115+
return this.client.submitEvent(this.target, this.pluginContextData);
116+
}
117+
118+
private isValidIdentifier(value:string): boolean {
119+
if (!value || !value.length) {
120+
return true;
121+
}
122+
123+
if (value.length < 8 || value.length > 100) {
124+
return false;
125+
}
126+
127+
for (var index = 0; index < value.length; index++) {
128+
var code = value.charCodeAt(index);
129+
var isDigit = (code >= 48) && (code <= 57);
130+
var isLetter = ((code >= 65) && (code <= 90)) || ((code >= 97) && (code <= 122));
131+
var isMinus = code === 45;
132+
133+
if (!(isDigit || isLetter) && !isMinus) {
134+
return false;
135+
}
136+
}
137+
138+
return true;
139+
}
140+
}
141+
}

src/ExceptionlessClient-spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path="references.ts" />
2+
3+
module Exceptionless {
4+
describe('ExceptionlessClient', () => {
5+
it('should use event reference ids', (done) => {
6+
var error = new Error('From Unit Test');
7+
8+
var client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
9+
expect(client.config.lastReferenceIdManager.getLast()).toBe(null);
10+
client.submitException(error).then(
11+
() => expect(client.config.lastReferenceIdManager.getLast()).toBe(null),
12+
() => expect(client.config.lastReferenceIdManager.getLast()).toBe(null)
13+
);
14+
15+
var numberOfPlugins = client.config.plugins.length;
16+
client.config.useReferenceIds();
17+
expect(client.config.plugins.length).toBe(numberOfPlugins + 1);
18+
19+
client.submitException(error)
20+
.then(
21+
() => expect(client.config.lastReferenceIdManager.getLast()).not.toBe(null),
22+
() => expect(client.config.lastReferenceIdManager.getLast()).toBe(null))
23+
.then(done);
24+
}, 5000);
25+
});
26+
}

0 commit comments

Comments
 (0)