Skip to content

ref(core): Delete API Details #4999

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 1 commit into from
Apr 27, 2022
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
10 changes: 5 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ However, directly importing from specific files is discouraged.

## Removing the `API` class from `@sentry/core`

The internal `API` class was removed in favor of the `initAPIDetails` function and the `APIDetails` type. More details can be found in the [PR that deprecated this class](https://github.com/getsentry/sentry-javascript/pull/4281). To migrate, see the following example.
The internal `API` class was removed in favor of using client options explicitly.

```js
// New in v7:
Expand All @@ -88,10 +88,10 @@ import {
getStoreEndpointWithUrlEncodedAuth,
} from '@sentry/core';

const dsn = initAPIDetails(dsn, metadata, tunnel);
const dsn = api.dsn;
const storeEndpoint = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
const envelopeEndpoint = getStoreEndpointWithUrlEncodedAuth(api.dsn);
const client = getCurrentHub().getClient();
const dsn = client.getDsn();
const options = client.getOptions();
const envelopeEndpoint = getEnvelopeEndpointWithUrlEncodedAuth(dsn, options.tunnel);

// Before:
import { API } from '@sentry/core';
Expand Down
26 changes: 1 addition & 25 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
import { DsnComponents, DsnLike, SdkMetadata } from '@sentry/types';
import { DsnComponents, DsnLike } from '@sentry/types';
import { dsnToString, makeDsn, urlEncode } from '@sentry/utils';

const SENTRY_API_VERSION = '7';

/**
* Stores details about a Sentry SDK
*/
export interface APIDetails {
/** The DSN as passed to Sentry.init() */
initDsn: DsnLike;
/** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
metadata: SdkMetadata;
/** The internally used Dsn object. */
readonly dsn: DsnComponents;
/** The envelope tunnel to use. */
readonly tunnel?: string;
}

/** Initializes API Details */
export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: string): APIDetails {
return {
initDsn: dsn,
metadata: metadata || {},
dsn: makeDsn(dsn),
tunnel,
} as APIDetails;
}

/** Returns the prefix to construct Sentry ingestion API endpoints. */
function getBaseApiEndpoint(dsn: DsnComponents): string {
const protocol = dsn.protocol ? `${dsn.protocol}:` : '';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export type { APIDetails } from './api';
export type { ClientClass } from './sdk';

export {
Expand All @@ -23,7 +22,7 @@ export {
Scope,
Session,
} from '@sentry/hub';
export { getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails, getReportDialogEndpoint } from './api';
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
export { BaseClient } from './baseclient';
export { initAndBind } from './sdk';
export { createTransport } from './transports/base';
Expand Down
19 changes: 4 additions & 15 deletions packages/core/test/lib/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/* eslint-disable deprecation/deprecation */
import { makeDsn } from '@sentry/utils';

import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint, initAPIDetails } from '../../src/api';
import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from '../../src/api';

const ingestDsn = 'https://[email protected]:1234/subpath/123';
const dsnPublic = 'https://[email protected]:1234/subpath/123';
const tunnel = 'https://hello.com/world';

const dsnPublicAPI = initAPIDetails(dsnPublic);
const dsnPublicComponents = makeDsn(dsnPublic);

describe('API', () => {
test('getEnvelopeEndpoint', () => {
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicComponents)).toEqual(
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7',
);
const dsnPublicAPIWithTunnel = initAPIDetails(dsnPublic, {}, tunnel);
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPIWithTunnel.dsn, tunnel)).toEqual(tunnel);
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicComponents, tunnel)).toEqual(tunnel);
});

describe('getReportDialogEndpoint', () => {
Expand Down Expand Up @@ -97,14 +96,4 @@ describe('API', () => {
},
);
});

test('initAPIDetails dsn', () => {
expect(dsnPublicAPI.dsn.host).toEqual(makeDsn(dsnPublic).host);
expect(dsnPublicAPI.dsn.path).toEqual(makeDsn(dsnPublic).path);
expect(dsnPublicAPI.dsn.pass).toEqual(makeDsn(dsnPublic).pass);
expect(dsnPublicAPI.dsn.port).toEqual(makeDsn(dsnPublic).port);
expect(dsnPublicAPI.dsn.protocol).toEqual(makeDsn(dsnPublic).protocol);
expect(dsnPublicAPI.dsn.projectId).toEqual(makeDsn(dsnPublic).projectId);
expect(dsnPublicAPI.dsn.publicKey).toEqual(makeDsn(dsnPublic).publicKey);
});
});