From 357515f47f1c15a5b845574a12f0b58e71960503 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 27 Apr 2022 12:01:41 -0400 Subject: [PATCH] ref(core): Delete API Details --- MIGRATION.md | 10 +++++----- packages/core/src/api.ts | 26 +------------------------- packages/core/src/index.ts | 3 +-- packages/core/test/lib/api.test.ts | 19 ++++--------------- 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 0a1141cf5cac..e7f2ecd7b028 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -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: @@ -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'; diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index 09dff0b8f291..dced7a8b181e 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -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}:` : ''; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 00123055009c..2c9eb53a9ef8 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,3 @@ -export type { APIDetails } from './api'; export type { ClientClass } from './sdk'; export { @@ -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'; diff --git a/packages/core/test/lib/api.test.ts b/packages/core/test/lib/api.test.ts index d556d9ec7cce..0a5ba52196e7 100644 --- a/packages/core/test/lib/api.test.ts +++ b/packages/core/test/lib/api.test.ts @@ -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://abc@xxxx.ingest.sentry.io:1234/subpath/123'; const dsnPublic = 'https://abc@sentry.io: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', () => { @@ -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); - }); });