Skip to content

DSN to Dsn casing change #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/browser/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class BrowserBackend implements Backend {
* @inheritDoc
*/
public install(): boolean {
// We are only called by the client if the SDK is enabled and a valid DSN
// has been configured. If no DSN is present, this indicates a programming
// We are only called by the client if the SDK is enabled and a valid Dsn
// has been configured. If no Dsn is present, this indicates a programming
// error.
const dsn = this.options.dsn;
if (!dsn) {
Expand Down Expand Up @@ -140,8 +140,8 @@ export class BrowserBackend implements Backend {
*/
public async sendEvent(event: SentryEvent): Promise<SentryResponse> {
if (!this.options.dsn) {
logger.warn(`Event has been skipped because no DSN is configured.`);
// We do nothing in case there is no DSN
logger.warn(`Event has been skipped because no Dsn is configured.`);
// We do nothing in case there is no Dsn
return { status: Status.Skipped };
}

Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API, BaseClient, SentryError } from '@sentry/core';
import { DSNLike } from '@sentry/types';
import { DsnLike } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
import { BrowserBackend, BrowserOptions } from './backend';

Expand All @@ -23,7 +23,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
public showReportDialog(options: {
[key: string]: any;
eventId?: string;
dsn?: DSNLike;
dsn?: DsnLike;
user?: {
email?: string;
name?: string;
Expand All @@ -47,14 +47,14 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
return;
}

const dsn = options.dsn || this.getDSN();
const dsn = options.dsn || this.getDsn();

if (!options.eventId) {
throw new SentryError('Missing `eventId` option in showReportDialog call');
}

if (!dsn) {
throw new SentryError('Missing `DSN` option in showReportDialog call');
throw new SentryError('Missing `Dsn` option in showReportDialog call');
}

const script = document.createElement('script');
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DSN } from '@sentry/core';
import { API } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { Integration, Severity } from '@sentry/types';
import { isFunction, isString } from '@sentry/utils/is';
Expand Down Expand Up @@ -354,8 +354,7 @@ export class Breadcrumbs implements Integration {
* Can be disabled or individually configured via the `autoBreadcrumbs` config option
*/
public install(options: BrowserOptions = {}): void {
// TODO: Use API provider instead of raw `new DSN`
const filterUrl = options.dsn && new DSN(options.dsn).user;
const filterUrl = options.dsn && new API(options.dsn).getStoreEndpoint();

if (this.config.console) {
this.instrumentConsole();
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const defaultIntegrations = [
* import { init } from '@sentry/browser';
*
* init({
* dsn: '__DSN__',
* dsn: '__Dsn__',
* // ...
* });
*
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/test/backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ let backend: BrowserBackend;

describe('BrowserBackend', () => {
describe('sendEvent()', () => {
it('should throw when no DSN is provided', async () => {
it('should throw when no Dsn is provided', async () => {
backend = new BrowserBackend({ dsn });

try {
await backend.sendEvent(testEvent);
} catch (e) {
expect(e.message).equal('Cannot sendEvent without a valid DSN');
expect(e.message).equal('Cannot sendEvent without a valid Dsn');
}
});

Expand Down
6 changes: 3 additions & 3 deletions packages/browser/test/transports/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai';
import { BaseTransport } from '../../src/transports/base';

const testDSN = 'https://[email protected]/42';
const testDsn = 'https://[email protected]/42';

class SimpleTransport extends BaseTransport {}

describe('BaseTransport', () => {
it('doesnt provide send() implementation', async () => {
const transport = new SimpleTransport({ dsn: testDSN });
const transport = new SimpleTransport({ dsn: testDsn });

try {
await transport.send({});
Expand All @@ -17,7 +17,7 @@ describe('BaseTransport', () => {
});

it('has correct endpoint url', () => {
const transport = new SimpleTransport({ dsn: testDSN });
const transport = new SimpleTransport({ dsn: testDsn });
expect(transport.url).equal('https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7');
});
});
4 changes: 2 additions & 2 deletions packages/browser/test/transports/beacon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { SinonStub, stub } from 'sinon';
import { Status, Transports } from '../../src';

const testDSN = 'https://[email protected]/42';
const testDsn = 'https://[email protected]/42';
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
const payload = {
event_id: '1337',
Expand All @@ -18,7 +18,7 @@ let transport: Transports.BaseTransport;
describe('BeaconTransport', () => {
beforeEach(() => {
sendBeacon = stub(window.navigator, 'sendBeacon');
transport = new Transports.BeaconTransport({ dsn: testDSN });
transport = new Transports.BeaconTransport({ dsn: testDsn });
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/test/transports/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { SinonStub, stub } from 'sinon';
import { Status, Transports } from '../../src';

const testDSN = 'https://[email protected]/42';
const testDsn = 'https://[email protected]/42';
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
const payload = {
event_id: '1337',
Expand All @@ -18,7 +18,7 @@ let transport: Transports.BaseTransport;
describe('FetchTransport', () => {
beforeEach(() => {
fetch = stub(window, 'fetch');
transport = new Transports.FetchTransport({ dsn: testDSN });
transport = new Transports.FetchTransport({ dsn: testDsn });
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/test/transports/xhr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { fakeServer, SinonFakeServer } from 'sinon';
import { Status, Transports } from '../../src';

const testDSN = 'https://[email protected]/42';
const testDsn = 'https://[email protected]/42';
const transportUrl = 'https://sentry.io/api/42/store/?sentry_key=123&sentry_version=7';
const payload = {
event_id: '1337',
Expand All @@ -19,7 +19,7 @@ describe('XHRTransport', () => {
beforeEach(() => {
server = fakeServer.create();
server.respondImmediately = true;
transport = new Transports.XHRTransport({ dsn: testDSN });
transport = new Transports.XHRTransport({ dsn: testDsn });
});

afterEach(() => {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { DSNLike } from '@sentry/types';
import { DsnLike } from '@sentry/types';
import { urlEncode } from '@sentry/utils/object';
import { DSN } from './dsn';
import { Dsn } from './dsn';

const SENTRY_API_VERSION = '7';

/** Helper class to provide urls to different Sentry endpoints. */
export class API {
/** The internally used DSN object. */
private readonly dsnObject: DSN;
/** The internally used Dsn object. */
private readonly dsnObject: Dsn;
/** Create a new instance of API */
public constructor(public dsn: DSNLike) {
this.dsnObject = new DSN(dsn);
public constructor(public dsn: DsnLike) {
this.dsnObject = new Dsn(dsn);
}

/** Returns the DSN object. */
public getDSN(): DSN {
/** Returns the Dsn object. */
public getDsn(): Dsn {
return this.dsnObject;
}

Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Scope } from '@sentry/hub';
import { Breadcrumb, SentryEvent, SentryEventHint, SentryResponse, Severity, Status } from '@sentry/types';
import { uuid4 } from '@sentry/utils/misc';
import { truncate } from '@sentry/utils/string';
import { DSN } from './dsn';
import { Dsn } from './dsn';
import { Backend, Client, Options } from './interfaces';

/**
Expand Down Expand Up @@ -35,10 +35,10 @@ export interface BackendClass<B extends Backend, O extends Options> {
* {@link Client.getOptions}. Also, the Backend instance is available via
* {@link Client.getBackend}.
*
* If a DSN is specified in the options, it will be parsed and stored. Use
* {@link Client.getDSN} to retrieve the DSN at any moment. In case the DSN is
* If a Dsn is specified in the options, it will be parsed and stored. Use
* {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is
* invalid, the constructor will throw a {@link SentryException}. Note that
* without a valid DSN, the SDK will not send any events to Sentry.
* without a valid Dsn, the SDK will not send any events to Sentry.
*
* Before sending an event via the backend, it is passed through
* {@link BaseClient.prepareEvent} to add SDK information and scope data
Expand Down Expand Up @@ -71,10 +71,10 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
private readonly options: O;

/**
* The client DSN, if specified in options. Without this DSN, the SDK will be
* The client Dsn, if specified in options. Without this Dsn, the SDK will be
* disabled.
*/
private readonly dsn?: DSN;
private readonly dsn?: Dsn;

/**
* Stores whether installation has been performed and was successful. Before
Expand All @@ -93,7 +93,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
this.options = options;

if (options.dsn) {
this.dsn = new DSN(options.dsn);
this.dsn = new Dsn(options.dsn);
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
/**
* @inheritDoc
*/
public getDSN(): DSN | undefined {
public getDsn(): Dsn | undefined {
return this.dsn;
}

Expand All @@ -183,7 +183,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
return this.backend;
}

/** Determines whether this SDK is enabled and a valid DSN is present. */
/** Determines whether this SDK is enabled and a valid Dsn is present. */
protected isEnabled(): boolean {
return this.getOptions().enabled !== false && this.dsn !== undefined;
}
Expand Down
34 changes: 17 additions & 17 deletions packages/core/src/dsn.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DSNComponents, DSNLike, DSNProtocol } from '@sentry/types';
import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
import { SentryError } from './error';

/** Regular expression used to parse a DSN. */
/** Regular expression used to parse a Dsn. */
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w\.-]+)(?::(\d+))?\/(.+)/;

/** The Sentry DSN, identifying a Sentry instance and project. */
export class DSN implements DSNComponents {
/** The Sentry Dsn, identifying a Sentry instance and project. */
export class Dsn implements DsnComponents {
/** Protocol used to connect to Sentry. */
public protocol!: DSNProtocol;
public protocol!: DsnProtocol;
/** Public authorization key. */
public user!: string;
/** Private authorization key (deprecated, optional). */
Expand All @@ -21,8 +21,8 @@ export class DSN implements DSNComponents {
/** Project ID */
public projectId!: string;

/** Creates a new DSN component */
public constructor(from: DSNLike) {
/** Creates a new Dsn component */
public constructor(from: DsnLike) {
if (typeof from === 'string') {
this.fromString(from);
} else {
Expand All @@ -33,7 +33,7 @@ export class DSN implements DSNComponents {
}

/**
* Renders the string representation of this DSN.
* Renders the string representation of this Dsn.
*
* By default, this will render the public representation without the password
* component. To get the deprecated private representation, set `withPassword`
Expand All @@ -50,11 +50,11 @@ export class DSN implements DSNComponents {
);
}

/** Parses a string into this DSN. */
/** Parses a string into this Dsn. */
private fromString(str: string): void {
const match = DSN_REGEX.exec(str);
if (!match) {
throw new SentryError('Invalid DSN');
throw new SentryError('Invalid Dsn');
}

const [protocol, user, pass = '', host, port = '', lastPath] = match.slice(1);
Expand All @@ -68,8 +68,8 @@ export class DSN implements DSNComponents {
Object.assign(this, { host, pass, path, projectId, port, protocol, user });
}

/** Maps DSN components into this instance. */
private fromComponents(components: DSNComponents): void {
/** Maps Dsn components into this instance. */
private fromComponents(components: DsnComponents): void {
this.protocol = components.protocol;
this.user = components.user;
this.pass = components.pass || '';
Expand All @@ -79,20 +79,20 @@ export class DSN implements DSNComponents {
this.projectId = components.projectId;
}

/** Validates this DSN and throws on error. */
/** Validates this Dsn and throws on error. */
private validate(): void {
for (const component of ['protocol', 'user', 'host', 'projectId']) {
if (!this[component as keyof DSNComponents]) {
throw new SentryError(`Invalid DSN: Missing ${component}`);
if (!this[component as keyof DsnComponents]) {
throw new SentryError(`Invalid Dsn: Missing ${component}`);
}
}

if (this.protocol !== 'http' && this.protocol !== 'https') {
throw new SentryError(`Invalid DSN: Unsupported protocol "${this.protocol}"`);
throw new SentryError(`Invalid Dsn: Unsupported protocol "${this.protocol}"`);
}

if (this.port && isNaN(parseInt(this.port, 10))) {
throw new SentryError(`Invalid DSN: Invalid port number "${this.port}"`);
throw new SentryError(`Invalid Dsn: Invalid port number "${this.port}"`);
}
}
}
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { captureException, captureMessage, configureScope } from '@sentry/minima
export { Hub, Scope } from '@sentry/hub';
export { API } from './api';
export { BackendClass, BaseClient } from './base';
export { DSN } from './dsn';
export { Dsn } from './dsn';
export { SentryError } from './error';
export { Backend, Client, LogLevel, Options } from './interfaces';
export { initAndBind, ClientClass } from './sdk';
8 changes: 4 additions & 4 deletions packages/core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
TransportClass,
TransportOptions,
} from '@sentry/types';
import { DSN } from './dsn';
import { Dsn } from './dsn';

/** Console logging verbosity for the SDK. */
export enum LogLevel {
Expand Down Expand Up @@ -40,7 +40,7 @@ export interface Options {
enabled?: boolean;

/**
* The DSN used to connect to Sentry and identify the project. If omitted, the
* The Dsn used to connect to Sentry and identify the project. If omitted, the
* SDK will not send any data to Sentry.
*/
dsn?: string;
Expand Down Expand Up @@ -189,8 +189,8 @@ export interface Client<O extends Options = Options> {
*/
addBreadcrumb(breadcrumb: Breadcrumb, scope?: Scope): void;

/** Returns the current DSN. */
getDSN(): DSN | undefined;
/** Returns the current Dsn. */
getDsn(): Dsn | undefined;

/** Returns the current options. */
getOptions(): O;
Expand Down
Loading