Skip to content

Commit 8e8455f

Browse files
committed
ref(utils): drop export
1 parent fddb78c commit 8e8455f

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

packages/core/src/api.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Dsn, DsnLike, SdkMetadata } from '@sentry/types';
2-
import { makeDsn, urlEncode } from '@sentry/utils';
1+
import { DsnComponents, DsnLike, SdkMetadata } from '@sentry/types';
2+
import { dsnToString, makeDsn, urlEncode } from '@sentry/utils';
33

44
const SENTRY_API_VERSION = '7';
55

@@ -12,7 +12,7 @@ export interface APIDetails {
1212
/** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
1313
metadata: SdkMetadata;
1414
/** The internally used Dsn object. */
15-
readonly dsn: Dsn;
15+
readonly dsn: DsnComponents;
1616
/** The envelope tunnel to use. */
1717
readonly tunnel?: string;
1818
}
@@ -32,7 +32,7 @@ export class API {
3232
public metadata: SdkMetadata;
3333

3434
/** The internally used Dsn object. */
35-
private readonly _dsnObject: Dsn;
35+
private readonly _dsnObject: DsnComponents;
3636

3737
/** The envelope tunnel to use. */
3838
private readonly _tunnel?: string;
@@ -46,7 +46,7 @@ export class API {
4646
}
4747

4848
/** Returns the Dsn object. */
49-
public getDsn(): Dsn {
49+
public getDsn(): DsnComponents {
5050
return this._dsnObject;
5151
}
5252

@@ -95,19 +95,19 @@ export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: st
9595
}
9696

9797
/** Returns the prefix to construct Sentry ingestion API endpoints. */
98-
function getBaseApiEndpoint(dsn: Dsn): string {
98+
function getBaseApiEndpoint(dsn: DsnComponents): string {
9999
const protocol = dsn.protocol ? `${dsn.protocol}:` : '';
100100
const port = dsn.port ? `:${dsn.port}` : '';
101101
return `${protocol}//${dsn.host}${port}${dsn.path ? `/${dsn.path}` : ''}/api/`;
102102
}
103103

104104
/** Returns the ingest API endpoint for target. */
105-
function _getIngestEndpoint(dsn: Dsn, target: 'store' | 'envelope'): string {
105+
function _getIngestEndpoint(dsn: DsnComponents, target: 'store' | 'envelope'): string {
106106
return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/${target}/`;
107107
}
108108

109109
/** Returns a URL-encoded string with auth config suitable for a query string. */
110-
function _encodedAuth(dsn: Dsn): string {
110+
function _encodedAuth(dsn: DsnComponents): string {
111111
return urlEncode({
112112
// We send only the minimum set of required information. See
113113
// https://github.com/getsentry/sentry-javascript/issues/2572.
@@ -117,7 +117,7 @@ function _encodedAuth(dsn: Dsn): string {
117117
}
118118

119119
/** Returns the store endpoint URL. */
120-
function getStoreEndpoint(dsn: Dsn): string {
120+
function getStoreEndpoint(dsn: DsnComponents): string {
121121
return _getIngestEndpoint(dsn, 'store');
122122
}
123123

@@ -126,12 +126,12 @@ function getStoreEndpoint(dsn: Dsn): string {
126126
*
127127
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
128128
*/
129-
export function getStoreEndpointWithUrlEncodedAuth(dsn: Dsn): string {
129+
export function getStoreEndpointWithUrlEncodedAuth(dsn: DsnComponents): string {
130130
return `${getStoreEndpoint(dsn)}?${_encodedAuth(dsn)}`;
131131
}
132132

133133
/** Returns the envelope endpoint URL. */
134-
function _getEnvelopeEndpoint(dsn: Dsn): string {
134+
function _getEnvelopeEndpoint(dsn: DsnComponents): string {
135135
return _getIngestEndpoint(dsn, 'envelope');
136136
}
137137

@@ -140,15 +140,19 @@ function _getEnvelopeEndpoint(dsn: Dsn): string {
140140
*
141141
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
142142
*/
143-
export function getEnvelopeEndpointWithUrlEncodedAuth(dsn: Dsn, tunnel?: string): string {
143+
export function getEnvelopeEndpointWithUrlEncodedAuth(dsn: DsnComponents, tunnel?: string): string {
144144
return tunnel ? tunnel : `${_getEnvelopeEndpoint(dsn)}?${_encodedAuth(dsn)}`;
145145
}
146146

147147
/**
148148
* Returns an object that can be used in request headers.
149149
* This is needed for node and the old /store endpoint in sentry
150150
*/
151-
export function getRequestHeaders(dsn: Dsn, clientName: string, clientVersion: string): { [key: string]: string } {
151+
export function getRequestHeaders(
152+
dsn: DsnComponents,
153+
clientName: string,
154+
clientVersion: string,
155+
): { [key: string]: string } {
152156
// CHANGE THIS to use metadata but keep clientName and clientVersion compatible
153157
const header = [`Sentry sentry_version=${SENTRY_API_VERSION}`];
154158
header.push(`sentry_client=${clientName}/${clientVersion}`);

packages/core/src/request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Event, SdkInfo, SentryRequest, SentryRequestType, Session, SessionAggregates } from '@sentry/types';
2+
import { dsnToString } from '@sentry/utils';
23

34
import { APIDetails, getEnvelopeEndpointWithUrlEncodedAuth, getStoreEndpointWithUrlEncodedAuth } from './api';
45

packages/types/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dsn } from './dsn';
1+
import { DsnLike } from './dsn';
22
import { Event, EventHint } from './event';
33
import { Integration, IntegrationClass } from './integration';
44
import { Options } from './options';
@@ -55,7 +55,7 @@ export interface Client<O extends Options = Options> {
5555
captureSession?(session: Session): void;
5656

5757
/** Returns the current Dsn. */
58-
getDsn(): Dsn | undefined;
58+
getDsn(): DsnLike | undefined;
5959

6060
/** Returns the current options. */
6161
getOptions(): O;

packages/utils/src/dsn.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dsn, DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
1+
import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
22

33
import { isDebugBuild } from './env';
44
import { SentryError } from './error';
@@ -19,15 +19,15 @@ function isValidProtocol(protocol?: string): protocol is DsnProtocol {
1919
*
2020
* @param withPassword When set to true, the password will be included.
2121
*/
22-
export function dsnToString(dsn: Dsn, withPassword: boolean = false): string {
22+
export function dsnToString(dsn: DsnComponents, withPassword: boolean = false): string {
2323
const { host, path, pass, port, projectId, protocol, publicKey } = dsn;
2424
return (
2525
`${protocol}://${publicKey}${withPassword && pass ? `:${pass}` : ''}` +
2626
`@${host}${port ? `:${port}` : ''}/${path ? `${path}/` : path}${projectId}`
2727
);
2828
}
2929

30-
function dsnFromString(str: string): Dsn {
30+
function dsnFromString(str: string): DsnComponents {
3131
const match = DSN_REGEX.exec(str);
3232

3333
if (!match) {
@@ -54,7 +54,7 @@ function dsnFromString(str: string): Dsn {
5454
return dsnFromComponents({ host, pass, path, projectId, port, protocol: protocol as DsnProtocol, publicKey });
5555
}
5656

57-
function dsnFromComponents(components: DsnComponents): Dsn {
57+
function dsnFromComponents(components: DsnComponents): DsnComponents {
5858
// TODO this is for backwards compatibility, and can be removed in a future version
5959
if ('user' in components && !('publicKey' in components)) {
6060
components.publicKey = components.user;
@@ -72,7 +72,7 @@ function dsnFromComponents(components: DsnComponents): Dsn {
7272
};
7373
}
7474

75-
function validateDsn(dsn: Dsn): boolean | void {
75+
function validateDsn(dsn: DsnComponents): boolean | void {
7676
if (!isDebugBuild()) {
7777
return;
7878
}
@@ -102,7 +102,7 @@ function validateDsn(dsn: Dsn): boolean | void {
102102
}
103103

104104
/** The Sentry Dsn, identifying a Sentry instance and project. */
105-
export function makeDsn(from: DsnLike): Dsn {
105+
export function makeDsn(from: DsnLike): DsnComponents {
106106
const components = typeof from === 'string' ? dsnFromString(from) : dsnFromComponents(from);
107107

108108
validateDsn(components);

0 commit comments

Comments
 (0)