Skip to content

Commit 5956d7f

Browse files
committed
ref(core): Delete API Details (#4999)
1 parent 2a2ca93 commit 5956d7f

File tree

4 files changed

+11
-47
lines changed

4 files changed

+11
-47
lines changed

MIGRATION.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ However, directly importing from specific files is discouraged.
7878

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

81-
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.
81+
The internal `API` class was removed in favor of using client options explicitly.
8282

8383
```js
8484
// New in v7:
@@ -88,10 +88,10 @@ import {
8888
getStoreEndpointWithUrlEncodedAuth,
8989
} from '@sentry/core';
9090

91-
const dsn = initAPIDetails(dsn, metadata, tunnel);
92-
const dsn = api.dsn;
93-
const storeEndpoint = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel);
94-
const envelopeEndpoint = getStoreEndpointWithUrlEncodedAuth(api.dsn);
91+
const client = getCurrentHub().getClient();
92+
const dsn = client.getDsn();
93+
const options = client.getOptions();
94+
const envelopeEndpoint = getEnvelopeEndpointWithUrlEncodedAuth(dsn, options.tunnel);
9595

9696
// Before:
9797
import { API } from '@sentry/core';

packages/core/src/api.ts

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
1-
import { DsnComponents, DsnLike, SdkMetadata } from '@sentry/types';
1+
import { DsnComponents, DsnLike } from '@sentry/types';
22
import { dsnToString, makeDsn, urlEncode } from '@sentry/utils';
33

44
const SENTRY_API_VERSION = '7';
55

6-
/**
7-
* Stores details about a Sentry SDK
8-
*/
9-
export interface APIDetails {
10-
/** The DSN as passed to Sentry.init() */
11-
initDsn: DsnLike;
12-
/** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
13-
metadata: SdkMetadata;
14-
/** The internally used Dsn object. */
15-
readonly dsn: DsnComponents;
16-
/** The envelope tunnel to use. */
17-
readonly tunnel?: string;
18-
}
19-
20-
/** Initializes API Details */
21-
export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: string): APIDetails {
22-
return {
23-
initDsn: dsn,
24-
metadata: metadata || {},
25-
dsn: makeDsn(dsn),
26-
tunnel,
27-
} as APIDetails;
28-
}
29-
306
/** Returns the prefix to construct Sentry ingestion API endpoints. */
317
function getBaseApiEndpoint(dsn: DsnComponents): string {
328
const protocol = dsn.protocol ? `${dsn.protocol}:` : '';

packages/core/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export type { APIDetails } from './api';
21
export type { ClientClass } from './sdk';
32

43
export {
@@ -23,7 +22,7 @@ export {
2322
Scope,
2423
Session,
2524
} from '@sentry/hub';
26-
export { getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails, getReportDialogEndpoint } from './api';
25+
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
2726
export { BaseClient } from './baseclient';
2827
export { initAndBind } from './sdk';
2928
export { createTransport } from './transports/base';

packages/core/test/lib/api.test.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
/* eslint-disable deprecation/deprecation */
22
import { makeDsn } from '@sentry/utils';
33

4-
import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint, initAPIDetails } from '../../src/api';
4+
import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from '../../src/api';
55

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

10-
const dsnPublicAPI = initAPIDetails(dsnPublic);
10+
const dsnPublicComponents = makeDsn(dsnPublic);
1111

1212
describe('API', () => {
1313
test('getEnvelopeEndpoint', () => {
14-
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
14+
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicComponents)).toEqual(
1515
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7',
1616
);
17-
const dsnPublicAPIWithTunnel = initAPIDetails(dsnPublic, {}, tunnel);
18-
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPIWithTunnel.dsn, tunnel)).toEqual(tunnel);
17+
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicComponents, tunnel)).toEqual(tunnel);
1918
});
2019

2120
describe('getReportDialogEndpoint', () => {
@@ -97,14 +96,4 @@ describe('API', () => {
9796
},
9897
);
9998
});
100-
101-
test('initAPIDetails dsn', () => {
102-
expect(dsnPublicAPI.dsn.host).toEqual(makeDsn(dsnPublic).host);
103-
expect(dsnPublicAPI.dsn.path).toEqual(makeDsn(dsnPublic).path);
104-
expect(dsnPublicAPI.dsn.pass).toEqual(makeDsn(dsnPublic).pass);
105-
expect(dsnPublicAPI.dsn.port).toEqual(makeDsn(dsnPublic).port);
106-
expect(dsnPublicAPI.dsn.protocol).toEqual(makeDsn(dsnPublic).protocol);
107-
expect(dsnPublicAPI.dsn.projectId).toEqual(makeDsn(dsnPublic).projectId);
108-
expect(dsnPublicAPI.dsn.publicKey).toEqual(makeDsn(dsnPublic).publicKey);
109-
});
11099
});

0 commit comments

Comments
 (0)