Skip to content

Commit e1afa76

Browse files
committed
browser: add BacktraceApi
1 parent d07b0aa commit e1afa76

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

packages/browser/src/BacktraceApi.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { BacktraceCoreApi, BacktraceCoreApiOptions } from '@backtrace/sdk-core';
2+
import {
3+
BacktraceBrowserRequestHandler,
4+
BacktraceBrowserRequestHandlerOptions,
5+
} from './BacktraceBrowserRequestHandler.js';
6+
7+
export interface BacktraceApiOptions extends BacktraceCoreApiOptions {
8+
readonly requestHandlerOptions?: BacktraceBrowserRequestHandlerOptions;
9+
}
10+
11+
export class BacktraceApi extends BacktraceCoreApi {
12+
constructor(options: BacktraceApiOptions) {
13+
super(options, options.requestHandler ?? new BacktraceBrowserRequestHandler(options.requestHandlerOptions));
14+
}
15+
}

packages/browser/src/BacktraceBrowserRequestHandler.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
DEFAULT_TIMEOUT,
88
} from '@backtrace/sdk-core';
99

10+
export interface BacktraceBrowserRequestHandlerOptions {
11+
readonly timeout?: number;
12+
}
13+
1014
export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
1115
private readonly UPLOAD_FILE_NAME = 'upload_file';
1216
private readonly _timeout: number;
@@ -18,14 +22,8 @@ export class BacktraceBrowserRequestHandler implements BacktraceRequestHandler {
1822
private readonly MULTIPART_HEADERS = {
1923
'Transfer-Encoding': 'chunked',
2024
};
21-
constructor(
22-
private readonly _options: {
23-
url: string;
24-
token?: string;
25-
timeout?: number;
26-
},
27-
) {
28-
this._timeout = this._options.timeout ?? DEFAULT_TIMEOUT;
25+
constructor(private readonly _options?: BacktraceBrowserRequestHandlerOptions) {
26+
this._timeout = this._options?.timeout ?? DEFAULT_TIMEOUT;
2927
}
3028
public async postError<T>(
3129
submissionUrl: string,

packages/browser/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ export {
1010
BacktraceStringAttachment,
1111
BacktraceUint8ArrayAttachment,
1212
BreadcrumbLogLevel,
13-
BreadcrumbType,
1413
BreadcrumbsEventSubscriber,
1514
BreadcrumbsManager,
15+
BreadcrumbType,
1616
JavaScriptEngine,
1717
RawBreadcrumb,
1818
SingleSessionProvider,
1919
V8StackTraceConverter,
2020
} from '@backtrace/sdk-core';
2121
export * from './agentDefinition.js';
22+
export * from './BacktraceApi.js';
2223
export * from './BacktraceBrowserRequestHandler.js';
2324
export * from './BacktraceClient.js';
2425
export * from './BacktraceConfiguration.js';

0 commit comments

Comments
 (0)