Skip to content

Commit 270a9e0

Browse files
committed
WIP - Submission client refactor (tests still need to be refactored)
1 parent 4d5de7b commit 270a9e0

Some content is hidden

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

41 files changed

+580
-886
lines changed

package-lock.json

Lines changed: 3 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/browser/src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {
22
IConfigurationSettings,
3-
Utils,
43
ExceptionlessClient,
54
Configuration,
6-
SettingsManager
5+
SettingsManager,
6+
parseQueryString
77
} from "@exceptionless/core";
88

99
import { DefaultErrorParser } from './services/DefaultErrorParser.js';
1010
import { DefaultModuleCollector } from './services/DefaultModuleCollector.js';
1111
import { DefaultRequestInfoCollector } from './services/DefaultRequestInfoCollector.js';
1212
import { BrowserStorage } from './storage/BrowserStorage.js';
1313
import { BrowserStorageProvider } from './storage/BrowserStorageProvider.js';
14-
import { DefaultSubmissionAdapter } from './submission/DefaultSubmissionAdapter.js';
14+
import { FetchSubmissionClient } from './submission/FetchSubmissionClient.js';
1515

1616
function init() {
1717
function getDefaultsSettingsFromScriptTag(): IConfigurationSettings {
@@ -22,7 +22,7 @@ function init() {
2222
const scripts = document.getElementsByTagName('script');
2323
for (let index = 0; index < scripts.length; index++) {
2424
if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
25-
return Utils.parseQueryString(scripts[index].src.split('?').pop());
25+
return parseQueryString(scripts[index].src.split('?').pop());
2626
}
2727
}
2828
return null;
@@ -82,7 +82,7 @@ function init() {
8282
defaults.errorParser = new DefaultErrorParser();
8383
defaults.moduleCollector = new DefaultModuleCollector();
8484
defaults.requestInfoCollector = new DefaultRequestInfoCollector();
85-
defaults.submissionAdapter = new DefaultSubmissionAdapter();
85+
defaults.submissionClient = new FetchSubmissionClient(ExceptionlessClient.default.config); // TODO: Figure out how to flow in the client settings.
8686

8787
//TraceKit.report.subscribe(processUnhandledException);
8888
//TraceKit.extendToAsynchronousCallbacks();
@@ -100,4 +100,6 @@ function init() {
100100
//declare var $;
101101

102102
init();
103+
104+
// TODO: Export all services
103105
export { ExceptionlessClient };

packages/browser/src/services/DefaultModuleCollector.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
IModule,
33
IModuleCollector,
4-
Utils
4+
getHashCode,
5+
parseVersion
56
} from '@exceptionless/core';
67

78
export class DefaultModuleCollector implements IModuleCollector {
@@ -18,13 +19,13 @@ export class DefaultModuleCollector implements IModuleCollector {
1819
modules.push({
1920
module_id: index,
2021
name: scripts[index].src.split('?')[0],
21-
version: Utils.parseVersion(scripts[index].src)
22+
version: parseVersion(scripts[index].src)
2223
});
2324
} else if (scripts[index].innerHTML) {
2425
modules.push({
2526
module_id: index,
2627
name: 'Script Tag',
27-
version: Utils.getHashCode(scripts[index].innerHTML).toString()
28+
version: getHashCode(scripts[index].innerHTML).toString()
2829
});
2930
}
3031
}

packages/browser/src/services/DefaultRequestInfoCollector.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
EventPluginContext,
33
IRequestInfo,
44
IRequestInfoCollector,
5-
Utils
5+
getCookies,
6+
parseQueryString
67
} from '@exceptionless/core';
78

89
export class DefaultRequestInfoCollector implements IRequestInfoCollector {
@@ -23,11 +24,11 @@ export class DefaultRequestInfoCollector implements IRequestInfoCollector {
2324
};
2425

2526
if (config.includeCookies) {
26-
requestInfo.cookies = Utils.getCookies(document.cookie, exclusions);
27+
requestInfo.cookies = getCookies(document.cookie, exclusions);
2728
}
2829

2930
if (config.includeQueryString) {
30-
requestInfo.query_string = Utils.parseQueryString(location.search.substring(1), exclusions);
31+
requestInfo.query_string = parseQueryString(location.search.substring(1), exclusions);
3132
}
3233

3334
if (document.referrer && document.referrer !== '') {

packages/browser/src/submission/DefaultSubmissionAdapter.ts

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
FetchOptions,
3+
Response,
4+
SubmissionClientBase
5+
} from '@exceptionless/core';
6+
7+
export class FetchSubmissionClient extends SubmissionClientBase {
8+
protected async fetch<T>(url: string, options: FetchOptions): Promise<Response<T>> {
9+
// TODO: Figure out how to set a 10000 timeout.
10+
const requestOptions: RequestInit = {
11+
method: options.method,
12+
headers: {
13+
'Accept': 'application/json',
14+
'Authorization': `client:${this.config.apiKey}`,
15+
'X-Exceptionless-Client': this.config.userAgent
16+
},
17+
body: options.body
18+
};
19+
20+
// TODO: Can we properly calculate content size?
21+
if (options.method === "POST") {
22+
requestOptions.headers['Content-Type'] = 'application/json';
23+
}
24+
25+
const response = await fetch(url, requestOptions);
26+
const settingsVersion: number = parseInt(response.headers.get(this.ConfigurationVersionHeader), 10);
27+
return new Response(response.status, response.statusText, settingsVersion, await response.json())
28+
}
29+
}

packages/core/src/EventBuilder.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IRequestInfo } from "./models/IRequestInfo.js";
55
import { IUserInfo } from './models/IUserInfo.js';
66
import { ContextData } from './plugins/ContextData.js';
77
import { EventPluginContext } from './plugins/EventPluginContext.js';
8-
import { Utils } from './Utils.js';
8+
import { addRange, stringify, isEmpty } from "./Utils.js";
99

1010
export class EventBuilder {
1111
public target: IEvent;
@@ -148,6 +148,11 @@ export class EventBuilder {
148148
return this;
149149
}
150150

151+
/**
152+
* Sets the event value.
153+
* @param value The value of the event.
154+
* @returns {EventBuilder}
155+
*/
151156
public setValue(value: number): EventBuilder {
152157
if (value) {
153158
this.target.value = value;
@@ -157,7 +162,7 @@ export class EventBuilder {
157162
}
158163

159164
public addTags(...tags: string[]): EventBuilder {
160-
this.target.tags = Utils.addRange<string>(this.target.tags, ...tags);
165+
this.target.tags = addRange<string>(this.target.tags, ...tags);
161166
return this;
162167
}
163168

@@ -178,8 +183,8 @@ export class EventBuilder {
178183
this.target.data = {};
179184
}
180185

181-
const result = JSON.parse(Utils.stringify(value, this.client.config.dataExclusions.concat(excludedPropertyNames || []), maxDepth));
182-
if (!Utils.isEmpty(result)) {
186+
const result = JSON.parse(stringify(value, this.client.config.dataExclusions.concat(excludedPropertyNames || []), maxDepth));
187+
if (!isEmpty(result)) {
183188
this.target.data[name] = result;
184189
}
185190

0 commit comments

Comments
 (0)