Skip to content

Commit 3f26bc7

Browse files
author
Luca Forstner
committed
feat(core): Deprecate validSeverityLevels
1 parent 2435b87 commit 3f26bc7

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

packages/core/src/api.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types';
22
import { dsnToString, makeDsn } from './utils-hoist/dsn';
3-
import { urlEncode } from './utils-hoist/object';
43

54
const SENTRY_API_VERSION = '7';
65

@@ -18,13 +17,21 @@ function _getIngestEndpoint(dsn: DsnComponents): string {
1817

1918
/** Returns a URL-encoded string with auth config suitable for a query string. */
2019
function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string {
21-
return urlEncode({
20+
const params: Record<string, string> = {
21+
sentry_version: SENTRY_API_VERSION,
22+
};
23+
24+
if (dsn.publicKey) {
2225
// We send only the minimum set of required information. See
2326
// https://github.com/getsentry/sentry-javascript/issues/2572.
24-
sentry_key: dsn.publicKey,
25-
sentry_version: SENTRY_API_VERSION,
26-
...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }),
27-
});
27+
params.sentry_key = dsn.publicKey;
28+
}
29+
30+
if (sdkInfo) {
31+
params.sentry_client = `${sdkInfo.name}/${sdkInfo.version}`;
32+
}
33+
34+
return new URLSearchParams(params).toString();
2835
}
2936

3037
/**

packages/core/src/utils-hoist/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export type {
8383
TransactionNamingScheme,
8484
} from './requestdata';
8585

86+
// eslint-disable-next-line deprecation/deprecation
8687
export { severityLevelFromString, validSeverityLevels } from './severity';
8788
export {
8889
UNKNOWN_FUNCTION,
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import type { SeverityLevel } from '@sentry/types';
22

3-
// Note: Ideally the `SeverityLevel` type would be derived from `validSeverityLevels`, but that would mean either
4-
//
5-
// a) moving `validSeverityLevels` to `@sentry/types`,
6-
// b) moving the`SeverityLevel` type here, or
7-
// c) importing `validSeverityLevels` from here into `@sentry/types`.
8-
//
9-
// Option A would make `@sentry/types` a runtime dependency of `@sentry/core` (not good), and options B and C would
10-
// create a circular dependency between `@sentry/types` and `@sentry/core` (also not good). So a TODO accompanying the
11-
// type, reminding anyone who changes it to change this list also, will have to do.
12-
3+
/**
4+
* @deprecated This variable has been deprecated and will be removed in the next major version.
5+
*/
136
export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'];
147

158
/**
@@ -19,5 +12,7 @@ export const validSeverityLevels = ['fatal', 'error', 'warning', 'log', 'info',
1912
* @returns The `SeverityLevel` corresponding to the given string, or 'log' if the string isn't a valid level.
2013
*/
2114
export function severityLevelFromString(level: SeverityLevel | string): SeverityLevel {
22-
return (level === 'warn' ? 'warning' : validSeverityLevels.includes(level) ? level : 'log') as SeverityLevel;
15+
return (
16+
level === 'warn' ? 'warning' : ['fatal', 'error', 'warning', 'log', 'info', 'debug'].includes(level) ? level : 'log'
17+
) as SeverityLevel;
2318
}

packages/core/test/utils-hoist/severity.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { severityLevelFromString, validSeverityLevels } from '../../src/utils-hoist/severity';
1+
import { severityLevelFromString } from '../../src/utils-hoist/severity';
22

33
describe('severityLevelFromString()', () => {
44
test("converts 'warn' to 'warning'", () => {
@@ -10,7 +10,7 @@ describe('severityLevelFromString()', () => {
1010
});
1111

1212
test('acts as a pass-through for valid level strings', () => {
13-
for (const level of validSeverityLevels) {
13+
for (const level of ['fatal', 'error', 'warning', 'log', 'info', 'debug']) {
1414
expect(severityLevelFromString(level)).toBe(level);
1515
}
1616
});

packages/types/src/severity.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
// Note: If this is ever changed, the `validSeverityLevels` array in `@sentry/core` needs to be changed, also. (See
2-
// note there for why we can't derive one from the other.)
31
export type SeverityLevel = 'fatal' | 'error' | 'warning' | 'log' | 'info' | 'debug';

0 commit comments

Comments
 (0)