Skip to content

Commit

Permalink
[v7] Remove API class, move Dsn to core and simplify it greatly
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Mar 22, 2021
1 parent 63f3f39 commit bd0e035
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 676 deletions.
6 changes: 3 additions & 3 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
import { BaseClient, ReportDialogOptions, Scope, SDK_VERSION } from '@sentry/core';
import { Event, EventHint } from '@sentry/types';
import { getGlobalObject, logger } from '@sentry/utils';

import { BrowserBackend, BrowserOptions } from './backend';
import { injectReportDialog, ReportDialogOptions } from './helpers';
import { injectReportDialog } from './helpers';
import { Breadcrumbs } from './integrations';

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {

injectReportDialog({
...options,
dsn: options.dsn || this.getDsn(),
dsn: options.dsn || this.getDsn()?.toString(),
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export {
configureScope,
getHubFromCarrier,
getCurrentHub,
getReportDialogEndpoint,
Hub,
makeMain,
ReportDialogOptions,
Scope,
startTransaction,
SDK_VERSION,
Expand All @@ -40,7 +42,7 @@ export {

export { BrowserOptions } from './backend';
export { BrowserClient } from './client';
export { injectReportDialog, ReportDialogOptions } from './helpers';
export { injectReportDialog } from './helpers';
export { eventFromException, eventFromMessage } from './eventbuilder';
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
export { SDK_NAME } from './version';
36 changes: 4 additions & 32 deletions packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API, captureException, withScope } from '@sentry/core';
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
import { captureException, Dsn, getReportDialogEndpoint, ReportDialogOptions, withScope } from '@sentry/core';
import { Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
import { addExceptionMechanism, addExceptionTypeValue, logger } from '@sentry/utils';

let ignoreOnError: number = 0;
Expand Down Expand Up @@ -160,39 +160,11 @@ export function wrap(
return sentryWrapped;
}

/**
* All properties the report dialog supports
*/
export interface ReportDialogOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
eventId?: string;
dsn?: DsnLike;
user?: {
email?: string;
name?: string;
};
lang?: string;
title?: string;
subtitle?: string;
subtitle2?: string;
labelName?: string;
labelEmail?: string;
labelComments?: string;
labelClose?: string;
labelSubmit?: string;
errorGeneric?: string;
errorFormEntry?: string;
successMessage?: string;
/** Callback after reportDialog showed up */
onLoad?(): void;
}

/**
* Injects the Report Dialog script
* @hidden
*/
export function injectReportDialog(options: ReportDialogOptions = {}): void {
export function injectReportDialog(options: ReportDialogOptions & { onLoad?(): void } = {}): void {
if (!options.eventId) {
logger.error(`Missing eventId option in showReportDialog call`);
return;
Expand All @@ -204,7 +176,7 @@ export function injectReportDialog(options: ReportDialogOptions = {}): void {

const script = document.createElement('script');
script.async = true;
script.src = new API(options.dsn).getReportDialogEndpoint(options);
script.src = getReportDialogEndpoint(new Dsn(options.dsn));

if (options.onLoad) {
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations, ReportDialogOptions } from '@sentry/core';
import { addInstrumentationHandler, getGlobalObject, logger, SyncPromise } from '@sentry/utils';

import { BrowserOptions } from './backend';
import { BrowserClient } from './client';
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
import { wrap as internalWrap } from './helpers';
import { Breadcrumbs, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';

export const defaultIntegrations = [
Expand Down
14 changes: 3 additions & 11 deletions packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { API } from '@sentry/core';
import {
Event,
Response as SentryResponse,
Expand All @@ -8,16 +7,11 @@ import {
TransportOptions,
} from '@sentry/types';
import { logger, parseRetryAfterHeader, PromiseBuffer, SentryError } from '@sentry/utils';
import { Dsn } from '@sentry/core';

/** Base Transport class implementation */
export abstract class BaseTransport implements Transport {
/**
* @deprecated
*/
public url: string;

/** Helper to get Sentry API endpoints. */
protected readonly _api: API;
protected readonly _dsn: Dsn;

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

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

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export class FetchTransport extends BaseTransport {
* @inheritDoc
*/
public sendEvent(event: Event): PromiseLike<Response> {
return this._sendRequest(eventToSentryRequest(event, this._api), event);
return this._sendRequest(eventToSentryRequest(event, this._dsn), event);
}

/**
* @inheritDoc
*/
public sendSession(session: Session): PromiseLike<Response> {
return this._sendRequest(sessionToSentryRequest(session, this._api), session);
return this._sendRequest(sessionToSentryRequest(session, this._dsn), session);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/transports/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export class XHRTransport extends BaseTransport {
* @inheritDoc
*/
public sendEvent(event: Event): PromiseLike<Response> {
return this._sendRequest(eventToSentryRequest(event, this._api), event);
return this._sendRequest(eventToSentryRequest(event, this._dsn), event);
}

/**
* @inheritDoc
*/
public sendSession(session: Session): PromiseLike<Response> {
return this._sendRequest(sessionToSentryRequest(session, this._api), session);
return this._sendRequest(sessionToSentryRequest(session, this._dsn), session);
}

/**
Expand Down
151 changes: 0 additions & 151 deletions packages/core/src/api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '@sentry/types';
import {
dateTimestampInSeconds,
Dsn,
isPrimitive,
isThenable,
logger,
Expand All @@ -23,6 +22,7 @@ import {
uuid4,
} from '@sentry/utils';

import { Dsn } from './dsn';
import { Backend, BackendClass } from './basebackend';
import { IntegrationIndex, setupIntegrations } from './integration';

Expand Down
Loading

0 comments on commit bd0e035

Please sign in to comment.