Skip to content

Commit ae974c9

Browse files
ejsmithniemyjski
authored andcommitted
Change models to classes and re-arrange folder structure (#96)
* Change models to classes and re-arrange folder structure * Combine error models into single file
1 parent aacdb5d commit ae974c9

Some content is hidden

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

44 files changed

+768
-506
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
"eslint.validate": [
2929
"javascript",
3030
"typescript"
31-
]
31+
],
32+
"deno.enable": false
3233
}

.vscode/tasks.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
{
77
"type": "npm",
88
"script": "clean",
9+
"problemMatcher": [],
10+
"label": "npm: clean"
911
},
1012
{
1113
"type": "npm",

packages/browser/src/services/DefaultErrorParser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
EventPluginContext,
3-
IError,
3+
ErrorInfo,
44
IErrorParser,
5-
IParameter,
6-
IStackFrame
5+
ParameterInfo,
6+
StackFrameInfo
77
} from '@exceptionless/core';
88

99
import {
@@ -12,21 +12,21 @@ import {
1212
} from 'stacktrace-js';
1313

1414
export class DefaultErrorParser implements IErrorParser {
15-
public async parse(context: EventPluginContext, exception: Error): Promise<IError> {
16-
function getParameters(parameters: string | string[]): IParameter[] {
15+
public async parse(context: EventPluginContext, exception: Error): Promise<ErrorInfo> {
16+
function getParameters(parameters: string | string[]): ParameterInfo[] {
1717
const params: string[] = (typeof parameters === 'string' ? [parameters] : parameters) || [];
1818

19-
const items: IParameter[] = [];
19+
const items: ParameterInfo[] = [];
2020
for (const param of params) {
2121
items.push({ name: param });
2222
}
2323

2424
return items;
2525
}
2626

27-
function getStackFrames(stackFrames: StackFrame[]): IStackFrame[] {
27+
function getStackFrames(stackFrames: StackFrame[]): StackFrameInfo[] {
2828
const ANONYMOUS: string = '<anonymous>';
29-
const frames: IStackFrame[] = [];
29+
const frames: StackFrameInfo[] = [];
3030

3131
for (const frame of stackFrames) {
3232
const fileName: string = frame.getFileName();

packages/browser/src/services/DefaultModuleCollector.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import {
2-
IModule,
3-
IModuleCollector,
42
getHashCode,
5-
parseVersion
6-
} from '@exceptionless/core';
3+
IModuleCollector,
4+
ModuleInfo,
5+
parseVersion,
6+
} from "@exceptionless/core";
77

88
export class DefaultModuleCollector implements IModuleCollector {
9-
public getModules(): IModule[] {
9+
public getModules(): ModuleInfo[] {
1010
if (!document || !document.getElementsByTagName) {
1111
return null;
1212
}
1313

14-
const modules: IModule[] = [];
15-
const scripts: HTMLCollectionOf<HTMLScriptElement> = document.getElementsByTagName('script');
14+
const modules: ModuleInfo[] = [];
15+
const scripts: HTMLCollectionOf<HTMLScriptElement> = document
16+
.getElementsByTagName("script");
1617
if (scripts && scripts.length > 0) {
1718
for (let index = 0; index < scripts.length; index++) {
1819
if (scripts[index].src) {
1920
modules.push({
2021
module_id: index,
21-
name: scripts[index].src.split('?')[0],
22-
version: parseVersion(scripts[index].src)
22+
name: scripts[index].src.split("?")[0],
23+
version: parseVersion(scripts[index].src),
2324
});
2425
} else if (scripts[index].innerHTML) {
2526
modules.push({
2627
module_id: index,
27-
name: 'Script Tag',
28-
version: getHashCode(scripts[index].innerHTML).toString()
28+
name: "Script Tag",
29+
version: getHashCode(scripts[index].innerHTML).toString(),
2930
});
3031
}
3132
}

packages/browser/src/services/DefaultRequestInfoCollector.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import {
22
EventPluginContext,
3-
IRequestInfo,
4-
IRequestInfoCollector,
53
getCookies,
6-
parseQueryString
7-
} from '@exceptionless/core';
4+
IRequestInfoCollector,
5+
parseQueryString,
6+
RequestInfo,
7+
} from "@exceptionless/core";
88

99
export class DefaultRequestInfoCollector implements IRequestInfoCollector {
10-
public getRequestInfo(context: EventPluginContext): IRequestInfo {
10+
public getRequestInfo(context: EventPluginContext): RequestInfo {
1111
if (!document || !navigator || !location) {
1212
return null;
1313
}
1414

1515
const config = context.client.config;
1616
const exclusions = config.dataExclusions;
17-
const requestInfo: IRequestInfo = {
17+
const requestInfo: RequestInfo = {
1818
user_agent: navigator.userAgent,
19-
is_secure: location.protocol === 'https:',
19+
is_secure: location.protocol === "https:",
2020
host: location.hostname,
21-
port: location.port && location.port !== '' ? parseInt(location.port, 10) : 80,
22-
path: location.pathname
21+
port: location.port && location.port !== ""
22+
? parseInt(location.port, 10)
23+
: 80,
24+
path: location.pathname,
2325
// client_ip_address: 'TODO'
2426
};
2527

@@ -28,10 +30,13 @@ export class DefaultRequestInfoCollector implements IRequestInfoCollector {
2830
}
2931

3032
if (config.includeQueryString) {
31-
requestInfo.query_string = parseQueryString(location.search.substring(1), exclusions);
33+
requestInfo.query_string = parseQueryString(
34+
location.search.substring(1),
35+
exclusions,
36+
);
3237
}
3338

34-
if (document.referrer && document.referrer !== '') {
39+
if (document.referrer && document.referrer !== "") {
3540
requestInfo.referrer = document.referrer;
3641
}
3742

packages/core/src/EventBuilder.ts

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
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";
99

1010
export class EventBuilder {
11-
public target: IEvent;
11+
public target: Event;
1212
public client: ExceptionlessClient;
1313
public pluginContextData: ContextData;
1414

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.
1617

17-
constructor(event: IEvent, client: ExceptionlessClient, pluginContextData?: ContextData) {
18+
constructor(
19+
event: Event,
20+
client: ExceptionlessClient,
21+
pluginContextData?: ContextData,
22+
) {
1823
this.target = event;
1924
this.client = client;
2025
this.pluginContextData = pluginContextData || new ContextData();
@@ -53,14 +58,14 @@ export class EventBuilder {
5358
*/
5459
public setEventReference(name: string, id: string): EventBuilder {
5560
if (!name) {
56-
throw new Error('Invalid name');
61+
throw new Error("Invalid name");
5762
}
5863

5964
if (!id || !this.isValidIdentifier(id)) {
6065
throw new Error(`Id ${this._validIdentifierErrorMessage}`);
6166
}
6267

63-
this.setProperty('@ref:' + name, id);
68+
this.setProperty("@ref:" + name, id);
6469
return this;
6570
}
6671

@@ -74,27 +79,34 @@ export class EventBuilder {
7479

7580
public setGeo(latitude: number, longitude: number): EventBuilder {
7681
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.");
7883
}
7984

8085
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+
);
8289
}
8390

8491
this.target.geo = `${latitude},${longitude}`;
8592
return this;
8693
}
8794

88-
public setUserIdentity(userInfo: IUserInfo): EventBuilder;
95+
public setUserIdentity(userInfo: UserInfo): EventBuilder;
8996
public setUserIdentity(identity: string): EventBuilder;
9097
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 };
93105
if (!userInfo || (!userInfo.identity && !userInfo.name)) {
94106
return this;
95107
}
96108

97-
this.setProperty('@user', userInfo);
109+
this.setProperty("@user", userInfo);
98110
return this;
99111
}
100112

@@ -105,9 +117,15 @@ export class EventBuilder {
105117
* @param description The user's description of the event.
106118
* @returns {EventBuilder}
107119
*/
108-
public setUserDescription(emailAddress: string, description: string): EventBuilder {
120+
public setUserDescription(
121+
emailAddress: string,
122+
description: string,
123+
): EventBuilder {
109124
if (emailAddress && description) {
110-
this.setProperty('@user_description', { email_address: emailAddress, description });
125+
this.setProperty("@user_description", {
126+
email_address: emailAddress,
127+
description,
128+
});
111129
}
112130

113131
return this;
@@ -120,14 +138,17 @@ export class EventBuilder {
120138
* @param title An optional title for the stacking information.
121139
* @returns {EventBuilder}
122140
*/
123-
public setManualStackingInfo(signatureData: any, title?: string): EventBuilder {
141+
public setManualStackingInfo(
142+
signatureData: any,
143+
title?: string,
144+
): EventBuilder {
124145
if (signatureData) {
125-
const stack: IManualStackingInfo = { signature_data: signatureData };
146+
const stack: ManualStackingInfo = { signature_data: signatureData };
126147
if (title) {
127148
stack.title = title;
128149
}
129150

130-
this.setProperty('@stack', stack);
151+
this.setProperty("@stack", stack);
131152
}
132153

133154
return this;
@@ -139,7 +160,10 @@ export class EventBuilder {
139160
* @param title An optional title for the stacking information.
140161
* @returns {EventBuilder}
141162
*/
142-
public setManualStackingKey(manualStackingKey: string, title?: string): EventBuilder {
163+
public setManualStackingKey(
164+
manualStackingKey: string,
165+
title?: string,
166+
): EventBuilder {
143167
if (manualStackingKey) {
144168
const data = { ManualStackingKey: manualStackingKey };
145169
this.setManualStackingInfo(data, title);
@@ -174,7 +198,12 @@ export class EventBuilder {
174198
* @param maxDepth The max depth of the object to include.
175199
* @param excludedPropertyNames Any property names that should be excluded.
176200
*/
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 {
178207
if (!name || (value === undefined || value == null)) {
179208
return this;
180209
}
@@ -183,7 +212,13 @@ export class EventBuilder {
183212
this.target.data = {};
184213
}
185214

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+
);
187222
if (!isEmpty(result)) {
188223
this.target.data[name] = result;
189224
}
@@ -193,15 +228,15 @@ export class EventBuilder {
193228

194229
public markAsCritical(critical: boolean): EventBuilder {
195230
if (critical) {
196-
this.addTags('Critical');
231+
this.addTags("Critical");
197232
}
198233

199234
return this;
200235
}
201236

202-
public addRequestInfo(request: IRequestInfo): EventBuilder {
237+
public addRequestInfo(request: RequestInfo): EventBuilder {
203238
if (request) {
204-
this.pluginContextData['@request'] = request;
239+
this.pluginContextData["@request"] = request;
205240
}
206241

207242
return this;
@@ -223,7 +258,8 @@ export class EventBuilder {
223258
for (let index = 0; index < value.length; index++) {
224259
const code = value.charCodeAt(index);
225260
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));
227263
const isMinus = code === 45;
228264

229265
if (!(isDigit || isLetter) && !isMinus) {

0 commit comments

Comments
 (0)