From 91080a618d1d07c7ac666f8055208e6c86f61094 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 21 Nov 2024 13:35:04 +0000 Subject: [PATCH 1/3] feat(core): Deprecate `urlEncode` --- packages/core/src/utils-hoist/index.ts | 1 + packages/core/src/utils-hoist/object.ts | 2 ++ packages/core/test/utils-hoist/object.test.ts | 3 +++ 3 files changed, 6 insertions(+) diff --git a/packages/core/src/utils-hoist/index.ts b/packages/core/src/utils-hoist/index.ts index 1625ea6c0868..b6bb7151a7e3 100644 --- a/packages/core/src/utils-hoist/index.ts +++ b/packages/core/src/utils-hoist/index.ts @@ -57,6 +57,7 @@ export { getOriginalFunction, markFunctionWrapped, objectify, + // eslint-disable-next-line deprecation/deprecation urlEncode, } from './object'; export { basename, dirname, isAbsolute, join, normalizePath, relative, resolve } from './path'; diff --git a/packages/core/src/utils-hoist/object.ts b/packages/core/src/utils-hoist/object.ts index 13ddff35664b..d3e785f7639d 100644 --- a/packages/core/src/utils-hoist/object.ts +++ b/packages/core/src/utils-hoist/object.ts @@ -90,6 +90,8 @@ export function getOriginalFunction(func: WrappedFunction): WrappedFunction | un * * @param object An object that contains serializable values * @returns string Encoded + * + * @deprecated This function is deprecated and will be removed in the next major version of the SDK. */ export function urlEncode(object: { [key: string]: any }): string { return Object.keys(object) diff --git a/packages/core/test/utils-hoist/object.test.ts b/packages/core/test/utils-hoist/object.test.ts index 7e39c463336c..2fadb530bdf2 100644 --- a/packages/core/test/utils-hoist/object.test.ts +++ b/packages/core/test/utils-hoist/object.test.ts @@ -130,14 +130,17 @@ describe('fill()', () => { describe('urlEncode()', () => { test('returns empty string for empty object input', () => { + // eslint-disable-next-line deprecation/deprecation expect(urlEncode({})).toEqual(''); }); test('returns single key/value pair joined with = sign', () => { + // eslint-disable-next-line deprecation/deprecation expect(urlEncode({ foo: 'bar' })).toEqual('foo=bar'); }); test('returns multiple key/value pairs joined together with & sign', () => { + // eslint-disable-next-line deprecation/deprecation expect(urlEncode({ foo: 'bar', pickle: 'rick', morty: '4 2' })).toEqual('foo=bar&pickle=rick&morty=4%202'); }); }); From a817581512c31111eebb74ec54162ac86d615544 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 22 Nov 2024 08:33:26 +0000 Subject: [PATCH 2/3] Actually remove usage --- packages/core/src/api.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/src/api.ts b/packages/core/src/api.ts index f8bb8cfe8eac..b7cd786d215a 100644 --- a/packages/core/src/api.ts +++ b/packages/core/src/api.ts @@ -1,6 +1,5 @@ import type { DsnComponents, DsnLike, SdkInfo } from '@sentry/types'; import { dsnToString, makeDsn } from './utils-hoist/dsn'; -import { urlEncode } from './utils-hoist/object'; const SENTRY_API_VERSION = '7'; @@ -18,13 +17,21 @@ function _getIngestEndpoint(dsn: DsnComponents): string { /** Returns a URL-encoded string with auth config suitable for a query string. */ function _encodedAuth(dsn: DsnComponents, sdkInfo: SdkInfo | undefined): string { - return urlEncode({ + const params: Record = { + sentry_version: SENTRY_API_VERSION, + }; + + if (dsn.publicKey) { // We send only the minimum set of required information. See // https://github.com/getsentry/sentry-javascript/issues/2572. - sentry_key: dsn.publicKey, - sentry_version: SENTRY_API_VERSION, - ...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }), - }); + params.sentry_key = dsn.publicKey; + } + + if (sdkInfo) { + params.sentry_client = `${sdkInfo.name}/${sdkInfo.version}`; + } + + return new URLSearchParams(params).toString(); } /** From e9135f34382ccf96ad08451bc9ec2bff2aa69a23 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 22 Nov 2024 08:48:38 +0000 Subject: [PATCH 3/3] test & lint --- docs/migration/draft-v9-migration-guide.md | 1 + packages/core/test/lib/api.test.ts | 4 ++-- packages/utils/src/index.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index d117d66ecae3..1b8cab48aec0 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -7,6 +7,7 @@ - Deprecated `AddRequestDataToEventOptions.transaction`. This option effectively doesn't do anything anymore, and will be removed in v9. - Deprecated `TransactionNamingScheme` type. +- Deprecated `urlEncode`. No replacements. ## `@sentry/core` diff --git a/packages/core/test/lib/api.test.ts b/packages/core/test/lib/api.test.ts index 2c581937cc42..89a8ad3cf20f 100644 --- a/packages/core/test/lib/api.test.ts +++ b/packages/core/test/lib/api.test.ts @@ -18,7 +18,7 @@ describe('API', () => { dsnPublicComponents, undefined, undefined, - 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7', + 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc', ], ['uses `tunnel` value when called with `tunnel` option', dsnPublicComponents, tunnel, undefined, tunnel], [ @@ -33,7 +33,7 @@ describe('API', () => { dsnPublicComponents, undefined, sdkInfo, - 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_key=abc&sentry_version=7&sentry_client=sentry.javascript.browser%2F12.31.12', + 'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc&sentry_client=sentry.javascript.browser%2F12.31.12', ], ])( '%s', diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 0b4bcd669706..17e2bb02aa99 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -149,6 +149,7 @@ export { memoBuilder, arrayify, normalizeUrlToBase, + // eslint-disable-next-line deprecation/deprecation urlEncode, // eslint-disable-next-line deprecation/deprecation extractPathForTransaction,