Skip to content

Commit bd0e035

Browse files
committed
[v7] Remove API class, move Dsn to core and simplify it greatly
1 parent 63f3f39 commit bd0e035

File tree

18 files changed

+353
-676
lines changed

18 files changed

+353
-676
lines changed

packages/browser/src/client.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
1+
import { BaseClient, ReportDialogOptions, Scope, SDK_VERSION } from '@sentry/core';
22
import { Event, EventHint } from '@sentry/types';
33
import { getGlobalObject, logger } from '@sentry/utils';
44

55
import { BrowserBackend, BrowserOptions } from './backend';
6-
import { injectReportDialog, ReportDialogOptions } from './helpers';
6+
import { injectReportDialog } from './helpers';
77
import { Breadcrumbs } from './integrations';
88

99
/**
@@ -53,7 +53,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5353

5454
injectReportDialog({
5555
...options,
56-
dsn: options.dsn || this.getDsn(),
56+
dsn: options.dsn || this.getDsn()?.toString(),
5757
});
5858
}
5959

packages/browser/src/exports.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export {
2424
configureScope,
2525
getHubFromCarrier,
2626
getCurrentHub,
27+
getReportDialogEndpoint,
2728
Hub,
2829
makeMain,
30+
ReportDialogOptions,
2931
Scope,
3032
startTransaction,
3133
SDK_VERSION,
@@ -40,7 +42,7 @@ export {
4042

4143
export { BrowserOptions } from './backend';
4244
export { BrowserClient } from './client';
43-
export { injectReportDialog, ReportDialogOptions } from './helpers';
45+
export { injectReportDialog } from './helpers';
4446
export { eventFromException, eventFromMessage } from './eventbuilder';
4547
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
4648
export { SDK_NAME } from './version';

packages/browser/src/helpers.ts

+4-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { API, captureException, withScope } from '@sentry/core';
2-
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
1+
import { captureException, Dsn, getReportDialogEndpoint, ReportDialogOptions, withScope } from '@sentry/core';
2+
import { Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
33
import { addExceptionMechanism, addExceptionTypeValue, logger } from '@sentry/utils';
44

55
let ignoreOnError: number = 0;
@@ -160,39 +160,11 @@ export function wrap(
160160
return sentryWrapped;
161161
}
162162

163-
/**
164-
* All properties the report dialog supports
165-
*/
166-
export interface ReportDialogOptions {
167-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
168-
[key: string]: any;
169-
eventId?: string;
170-
dsn?: DsnLike;
171-
user?: {
172-
email?: string;
173-
name?: string;
174-
};
175-
lang?: string;
176-
title?: string;
177-
subtitle?: string;
178-
subtitle2?: string;
179-
labelName?: string;
180-
labelEmail?: string;
181-
labelComments?: string;
182-
labelClose?: string;
183-
labelSubmit?: string;
184-
errorGeneric?: string;
185-
errorFormEntry?: string;
186-
successMessage?: string;
187-
/** Callback after reportDialog showed up */
188-
onLoad?(): void;
189-
}
190-
191163
/**
192164
* Injects the Report Dialog script
193165
* @hidden
194166
*/
195-
export function injectReportDialog(options: ReportDialogOptions = {}): void {
167+
export function injectReportDialog(options: ReportDialogOptions & { onLoad?(): void } = {}): void {
196168
if (!options.eventId) {
197169
logger.error(`Missing eventId option in showReportDialog call`);
198170
return;
@@ -204,7 +176,7 @@ export function injectReportDialog(options: ReportDialogOptions = {}): void {
204176

205177
const script = document.createElement('script');
206178
script.async = true;
207-
script.src = new API(options.dsn).getReportDialogEndpoint(options);
179+
script.src = getReportDialogEndpoint(new Dsn(options.dsn));
208180

209181
if (options.onLoad) {
210182
// eslint-disable-next-line @typescript-eslint/unbound-method

packages/browser/src/sdk.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
1+
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations, ReportDialogOptions } from '@sentry/core';
22
import { addInstrumentationHandler, getGlobalObject, logger, SyncPromise } from '@sentry/utils';
33

44
import { BrowserOptions } from './backend';
55
import { BrowserClient } from './client';
6-
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
6+
import { wrap as internalWrap } from './helpers';
77
import { Breadcrumbs, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
88

99
export const defaultIntegrations = [

packages/browser/src/transports/base.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { API } from '@sentry/core';
21
import {
32
Event,
43
Response as SentryResponse,
@@ -8,16 +7,11 @@ import {
87
TransportOptions,
98
} from '@sentry/types';
109
import { logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';
10+
import { Dsn } from '@sentry/core';
1111

1212
/** Base Transport class implementation */
1313
export abstract class BaseTransport implements Transport {
14-
/**
15-
* @deprecated
16-
*/
17-
public url: string;
18-
19-
/** Helper to get Sentry API endpoints. */
20-
protected readonly _api: API;
14+
protected readonly _dsn: Dsn;
2115

2216
/** A simple buffer holding all requests. */
2317
protected readonly _buffer: PromiseBuffer<SentryResponse> = new PromiseBuffer(30);
@@ -26,9 +20,7 @@ export abstract class BaseTransport implements Transport {
2620
protected readonly _rateLimits: Record<string, Date> = {};
2721

2822
public constructor(public options: TransportOptions) {
29-
this._api = new API(options.dsn, options._metadata);
30-
// eslint-disable-next-line deprecation/deprecation
31-
this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
23+
this._dsn = new Dsn(options.dsn as string);
3224
}
3325

3426
/**

packages/browser/src/transports/fetch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export class FetchTransport extends BaseTransport {
9090
* @inheritDoc
9191
*/
9292
public sendEvent(event: Event): PromiseLike<Response> {
93-
return this._sendRequest(eventToSentryRequest(event, this._api), event);
93+
return this._sendRequest(eventToSentryRequest(event, this._dsn), event);
9494
}
9595

9696
/**
9797
* @inheritDoc
9898
*/
9999
public sendSession(session: Session): PromiseLike<Response> {
100-
return this._sendRequest(sessionToSentryRequest(session, this._api), session);
100+
return this._sendRequest(sessionToSentryRequest(session, this._dsn), session);
101101
}
102102

103103
/**

packages/browser/src/transports/xhr.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export class XHRTransport extends BaseTransport {
1010
* @inheritDoc
1111
*/
1212
public sendEvent(event: Event): PromiseLike<Response> {
13-
return this._sendRequest(eventToSentryRequest(event, this._api), event);
13+
return this._sendRequest(eventToSentryRequest(event, this._dsn), event);
1414
}
1515

1616
/**
1717
* @inheritDoc
1818
*/
1919
public sendSession(session: Session): PromiseLike<Response> {
20-
return this._sendRequest(sessionToSentryRequest(session, this._api), session);
20+
return this._sendRequest(sessionToSentryRequest(session, this._dsn), session);
2121
}
2222

2323
/**

packages/core/src/api.ts

-151
This file was deleted.

packages/core/src/baseclient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from '@sentry/types';
1313
import {
1414
dateTimestampInSeconds,
15-
Dsn,
1615
isPrimitive,
1716
isThenable,
1817
logger,
@@ -23,6 +22,7 @@ import {
2322
uuid4,
2423
} from '@sentry/utils';
2524

25+
import { Dsn } from './dsn';
2626
import { Backend, BackendClass } from './basebackend';
2727
import { IntegrationIndex, setupIntegrations } from './integration';
2828

0 commit comments

Comments
 (0)