Skip to content

Commit 47fb065

Browse files
committed
ref(core): Delete API class (#4848)
Removes the deprecated `API` class.
1 parent 1789080 commit 47fb065

File tree

3 files changed

+26
-84
lines changed

3 files changed

+26
-84
lines changed

packages/core/src/api.ts

+1-68
Original file line numberDiff line numberDiff line change
@@ -17,73 +17,6 @@ export interface APIDetails {
1717
readonly tunnel?: string;
1818
}
1919

20-
/**
21-
* Helper class to provide urls, headers and metadata that can be used to form
22-
* different types of requests to Sentry endpoints.
23-
* Supports both envelopes and regular event requests.
24-
*
25-
* @deprecated Please use APIDetails
26-
**/
27-
export class API {
28-
/** The DSN as passed to Sentry.init() */
29-
public dsn: DsnLike;
30-
31-
/** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
32-
public metadata: SdkMetadata;
33-
34-
/** The internally used Dsn object. */
35-
private readonly _dsnObject: DsnComponents;
36-
37-
/** The envelope tunnel to use. */
38-
private readonly _tunnel?: string;
39-
40-
/** Create a new instance of API */
41-
public constructor(dsn: DsnLike, metadata: SdkMetadata = {}, tunnel?: string) {
42-
this.dsn = dsn;
43-
this._dsnObject = makeDsn(dsn);
44-
this.metadata = metadata;
45-
this._tunnel = tunnel;
46-
}
47-
48-
/** Returns the Dsn object. */
49-
public getDsn(): DsnComponents {
50-
return this._dsnObject;
51-
}
52-
53-
/** Does this transport force envelopes? */
54-
public forceEnvelope(): boolean {
55-
return !!this._tunnel;
56-
}
57-
58-
/** Returns the prefix to construct Sentry ingestion API endpoints. */
59-
public getBaseApiEndpoint(): string {
60-
return getBaseApiEndpoint(this._dsnObject);
61-
}
62-
63-
/** Returns the store endpoint URL. */
64-
public getStoreEndpoint(): string {
65-
return getStoreEndpoint(this._dsnObject);
66-
}
67-
68-
/**
69-
* Returns the store endpoint URL with auth in the query string.
70-
*
71-
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
72-
*/
73-
public getStoreEndpointWithUrlEncodedAuth(): string {
74-
return getStoreEndpointWithUrlEncodedAuth(this._dsnObject);
75-
}
76-
77-
/**
78-
* Returns the envelope endpoint URL with auth in the query string.
79-
*
80-
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
81-
*/
82-
public getEnvelopeEndpointWithUrlEncodedAuth(): string {
83-
return getEnvelopeEndpointWithUrlEncodedAuth(this._dsnObject, this._tunnel);
84-
}
85-
}
86-
8720
/** Initializes API Details */
8821
export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: string): APIDetails {
8922
return {
@@ -117,7 +50,7 @@ function _encodedAuth(dsn: DsnComponents): string {
11750
}
11851

11952
/** Returns the store endpoint URL. */
120-
function getStoreEndpoint(dsn: DsnComponents): string {
53+
export function getStoreEndpoint(dsn: DsnComponents): string {
12154
return _getIngestEndpoint(dsn, 'store');
12255
}
12356

packages/core/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export {
1515
} from '@sentry/minimal';
1616
export { addGlobalEventProcessor, getCurrentHub, getHubFromCarrier, Hub, makeMain, Scope, Session } from '@sentry/hub';
1717
export {
18-
// eslint-disable-next-line deprecation/deprecation
19-
API,
2018
APIDetails,
2119
getEnvelopeEndpointWithUrlEncodedAuth,
2220
getStoreEndpointWithUrlEncodedAuth,

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
/* eslint-disable deprecation/deprecation */
22
import { makeDsn } from '@sentry/utils';
33

4-
import { API, getReportDialogEndpoint, getRequestHeaders } from '../../src/api';
4+
import {
5+
getEnvelopeEndpointWithUrlEncodedAuth,
6+
getReportDialogEndpoint,
7+
getRequestHeaders,
8+
getStoreEndpoint,
9+
getStoreEndpointWithUrlEncodedAuth,
10+
initAPIDetails,
11+
} from '../../src/api';
512

613
const ingestDsn = 'https://[email protected]:1234/subpath/123';
714
const dsnPublic = 'https://[email protected]:1234/subpath/123';
815
const legacyDsn = 'https://abc:[email protected]:1234/subpath/123';
916
const tunnel = 'https://hello.com/world';
1017

18+
const ingestDsnAPI = initAPIDetails(ingestDsn);
19+
const dsnPublicAPI = initAPIDetails(dsnPublic);
20+
1121
describe('API', () => {
1222
test('getStoreEndpoint', () => {
13-
expect(new API(dsnPublic).getStoreEndpointWithUrlEncodedAuth()).toEqual(
23+
expect(getStoreEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
1424
'https://sentry.io:1234/subpath/api/123/store/?sentry_key=abc&sentry_version=7',
1525
);
16-
expect(new API(dsnPublic).getStoreEndpoint()).toEqual('https://sentry.io:1234/subpath/api/123/store/');
17-
expect(new API(ingestDsn).getStoreEndpoint()).toEqual('https://xxxx.ingest.sentry.io:1234/subpath/api/123/store/');
26+
expect(getStoreEndpoint(dsnPublicAPI.dsn)).toEqual('https://sentry.io:1234/subpath/api/123/store/');
27+
expect(getStoreEndpoint(ingestDsnAPI.dsn)).toEqual('https://xxxx.ingest.sentry.io:1234/subpath/api/123/store/');
1828
});
1929

2030
test('getEnvelopeEndpoint', () => {
21-
expect(new API(dsnPublic).getEnvelopeEndpointWithUrlEncodedAuth()).toEqual(
31+
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPI.dsn)).toEqual(
2232
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7',
2333
);
24-
expect(new API(dsnPublic, {}, tunnel).getEnvelopeEndpointWithUrlEncodedAuth()).toEqual(tunnel);
34+
const dsnPublicAPIWithTunnel = initAPIDetails(dsnPublic, {}, tunnel);
35+
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnPublicAPIWithTunnel.dsn, tunnel)).toEqual(tunnel);
2536
});
2637

2738
test('getRequestHeaders', () => {
@@ -118,13 +129,13 @@ describe('API', () => {
118129
);
119130
});
120131

121-
test('getDsn', () => {
122-
expect(new API(dsnPublic).getDsn().host).toEqual(makeDsn(dsnPublic).host);
123-
expect(new API(dsnPublic).getDsn().path).toEqual(makeDsn(dsnPublic).path);
124-
expect(new API(dsnPublic).getDsn().pass).toEqual(makeDsn(dsnPublic).pass);
125-
expect(new API(dsnPublic).getDsn().port).toEqual(makeDsn(dsnPublic).port);
126-
expect(new API(dsnPublic).getDsn().protocol).toEqual(makeDsn(dsnPublic).protocol);
127-
expect(new API(dsnPublic).getDsn().projectId).toEqual(makeDsn(dsnPublic).projectId);
128-
expect(new API(dsnPublic).getDsn().publicKey).toEqual(makeDsn(dsnPublic).publicKey);
132+
test('initAPIDetails dsn', () => {
133+
expect(dsnPublicAPI.dsn.host).toEqual(makeDsn(dsnPublic).host);
134+
expect(dsnPublicAPI.dsn.path).toEqual(makeDsn(dsnPublic).path);
135+
expect(dsnPublicAPI.dsn.pass).toEqual(makeDsn(dsnPublic).pass);
136+
expect(dsnPublicAPI.dsn.port).toEqual(makeDsn(dsnPublic).port);
137+
expect(dsnPublicAPI.dsn.protocol).toEqual(makeDsn(dsnPublic).protocol);
138+
expect(dsnPublicAPI.dsn.projectId).toEqual(makeDsn(dsnPublic).projectId);
139+
expect(dsnPublicAPI.dsn.publicKey).toEqual(makeDsn(dsnPublic).publicKey);
129140
});
130141
});

0 commit comments

Comments
 (0)