From d9184c9e60370e60cd8a2171230a0ec67a0d3416 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 15:23:47 +0300 Subject: [PATCH 01/11] chore(backend): Warn about frontendApi deprecation --- packages/backend/src/redirections.ts | 4 +++- packages/backend/src/tokens/interstitial.ts | 12 ++++++++++++ packages/backend/src/tokens/request.ts | 6 +++++- packages/backend/src/util/shared.ts | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/redirections.ts b/packages/backend/src/redirections.ts index 76f96b7c12b..d5a96877774 100644 --- a/packages/backend/src/redirections.ts +++ b/packages/backend/src/redirections.ts @@ -1,4 +1,4 @@ -import { errorThrower, parsePublishableKey } from './util/shared'; +import { deprecated, errorThrower, parsePublishableKey } from './util/shared'; type RedirectAdapter = (url: string) => any; @@ -39,6 +39,8 @@ type RedirectParams = { export function redirect({ redirectAdapter, signUpUrl, signInUrl, frontendApi, publishableKey }: RedirectParams) { if (!frontendApi) { frontendApi = parsePublishableKey(publishableKey)?.frontendApi; + } else { + deprecated('frontentApi', 'Use `publishableKey` instead.'); } const accountsBaseUrl = buildAccountsBaseUrl(frontendApi); diff --git a/packages/backend/src/tokens/interstitial.ts b/packages/backend/src/tokens/interstitial.ts index b5d434fbddb..b6da5369326 100644 --- a/packages/backend/src/tokens/interstitial.ts +++ b/packages/backend/src/tokens/interstitial.ts @@ -8,6 +8,7 @@ import { joinPaths } from '../util/path'; import { addClerkPrefix, callWithRetry, + deprecated, getClerkJsMajorVersionOrTag, getScriptUrl, isDevOrStagingUrl, @@ -33,6 +34,10 @@ export type LoadInterstitialOptions = { } & MultiDomainAndOrProxyPrimitives; export function loadInterstitialFromLocal(options: Omit) { + if (options.frontendApi) { + deprecated('frontentApi', 'Use `publishableKey` instead.'); + } + options.frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi || ''; const domainOnlyInProd = !isDevOrStagingUrl(options.frontendApi) ? addClerkPrefix(options.domain) : ''; const { @@ -126,6 +131,9 @@ export function loadInterstitialFromLocal(options: Omit @@ -149,6 +157,10 @@ export async function loadInterstitialFromBAPI(options: LoadInterstitialOptions) } export function buildPublicInterstitialUrl(options: LoadInterstitialOptions) { + if (options.frontendApi) { + deprecated('frontentApi', 'Use `publishableKey` instead.'); + } + options.frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi || ''; const { apiUrl, frontendApi, pkgVersion, clerkJSVersion, publishableKey, proxyUrl, isSatellite, domain, signInUrl } = options; diff --git a/packages/backend/src/tokens/request.ts b/packages/backend/src/tokens/request.ts index 991677b2700..4d186ff339b 100644 --- a/packages/backend/src/tokens/request.ts +++ b/packages/backend/src/tokens/request.ts @@ -1,7 +1,7 @@ import { API_URL, API_VERSION, constants } from '../constants'; import { assertValidSecretKey } from '../util/assertValidSecretKey'; import { buildRequest, stripAuthorizationHeader } from '../util/IsomorphicRequest'; -import { isDevelopmentFromApiKey, parsePublishableKey } from '../util/shared'; +import { deprecated, isDevelopmentFromApiKey, parsePublishableKey } from '../util/shared'; import type { RequestState } from './authStatus'; import { AuthErrorReason, interstitial, signedOut, unknownState } from './authStatus'; import type { TokenCarrier } from './errors'; @@ -120,6 +120,10 @@ function assertProxyUrlOrDomain(proxyUrlOrDomain: string | undefined) { export async function authenticateRequest(options: AuthenticateRequestOptions): Promise { const { cookies, headers, searchParams } = buildRequest(options?.request); + if (options.frontendApi) { + deprecated('frontentApi', 'Use `publishableKey` instead.'); + } + options = { ...options, frontendApi: parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi, diff --git a/packages/backend/src/util/shared.ts b/packages/backend/src/util/shared.ts index 0da270edba0..1a8d1b90711 100644 --- a/packages/backend/src/util/shared.ts +++ b/packages/backend/src/util/shared.ts @@ -6,6 +6,7 @@ export { isDevelopmentFromApiKey, isProductionFromApiKey, parsePublishableKey, + deprecated, } from '@clerk/shared'; import { buildErrorThrower } from '@clerk/shared'; From d0a602fd93d943853e772132693b8645a1545cb4 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 15:39:16 +0300 Subject: [PATCH 02/11] chore(backend): Warn about apiKey deprecation --- packages/backend/src/api/request.ts | 4 ++++ packages/backend/src/tokens/request.ts | 4 ++++ packages/backend/src/tokens/verify.ts | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/packages/backend/src/api/request.ts b/packages/backend/src/api/request.ts index 130d47c0596..6fcf07d6f49 100644 --- a/packages/backend/src/api/request.ts +++ b/packages/backend/src/api/request.ts @@ -8,6 +8,7 @@ import { API_URL, API_VERSION, constants, USER_AGENT } from '../constants'; import runtime from '../runtime'; import { assertValidSecretKey } from '../util/assertValidSecretKey'; import { joinPaths } from '../util/path'; +import { deprecated } from '../util/shared'; import type { CreateBackendApiOptions } from './factory'; import { deserialize } from './resources/Deserializer'; @@ -72,6 +73,9 @@ export function buildRequest(options: CreateBackendApiOptions) { userAgent = USER_AGENT, httpOptions = {}, } = options; + if (apiKey) { + deprecated('apiKey', 'Use `secretKey` instead.'); + } const { path, method, queryParams, headerParams, bodyParams, formData } = requestOptions; const key = secretKey || apiKey; diff --git a/packages/backend/src/tokens/request.ts b/packages/backend/src/tokens/request.ts index 4d186ff339b..45ef18b409b 100644 --- a/packages/backend/src/tokens/request.ts +++ b/packages/backend/src/tokens/request.ts @@ -124,6 +124,10 @@ export async function authenticateRequest(options: AuthenticateRequestOptions): deprecated('frontentApi', 'Use `publishableKey` instead.'); } + if (options.apiKey) { + deprecated('apiKey', 'Use `secretKey` instead.'); + } + options = { ...options, frontendApi: parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi, diff --git a/packages/backend/src/tokens/verify.ts b/packages/backend/src/tokens/verify.ts index 96290c11648..eaa565306c8 100644 --- a/packages/backend/src/tokens/verify.ts +++ b/packages/backend/src/tokens/verify.ts @@ -1,5 +1,6 @@ import type { JwtPayload } from '@clerk/types'; +import { deprecated } from '../util/shared'; import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from './errors'; import type { VerifyJwtOptions } from './jwt'; import { decodeJwt, verifyJwt } from './jwt'; @@ -33,6 +34,10 @@ export async function verifyToken(token: string, options: VerifyTokenOptions): P skipJwksCache, } = options; + if (options.apiKey) { + deprecated('apiKey', 'Use `secretKey` instead.'); + } + const { header } = decodeJwt(token); const { kid } = header; From 1d0c810c748845501d5fea748349c78e0b5d8225 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 15:53:03 +0300 Subject: [PATCH 03/11] chore(backend): Warn about httpOptions deprecation --- packages/backend/src/api/request.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/api/request.ts b/packages/backend/src/api/request.ts index 6fcf07d6f49..fee69a39486 100644 --- a/packages/backend/src/api/request.ts +++ b/packages/backend/src/api/request.ts @@ -68,14 +68,21 @@ export function buildRequest(options: CreateBackendApiOptions) { const { apiKey, secretKey, + httpOptions, apiUrl = API_URL, apiVersion = API_VERSION, userAgent = USER_AGENT, - httpOptions = {}, } = options; if (apiKey) { deprecated('apiKey', 'Use `secretKey` instead.'); } + if (httpOptions) { + deprecated( + 'httpOptions', + 'This option has been deprecated and will be removed with the next major release.\nA RequestInit init object used by the `request` method.', + ); + } + const { path, method, queryParams, headerParams, bodyParams, formData } = requestOptions; const key = secretKey || apiKey; @@ -123,7 +130,7 @@ export function buildRequest(options: CreateBackendApiOptions) { res = await runtime.fetch( finalUrl.href, - deepmerge(httpOptions, { + deepmerge(httpOptions || {}, { method, headers, ...body, From 5223843698d38f712ed3b668e517b33085961bdd Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 15:59:28 +0300 Subject: [PATCH 04/11] chore(backend): Warn about InterstitialAPI deprecation --- packages/backend/src/api/endpoints/InterstitialApi.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/api/endpoints/InterstitialApi.ts b/packages/backend/src/api/endpoints/InterstitialApi.ts index 49bae182153..2ce6cc967c3 100644 --- a/packages/backend/src/api/endpoints/InterstitialApi.ts +++ b/packages/backend/src/api/endpoints/InterstitialApi.ts @@ -1,10 +1,15 @@ +import { deprecated } from '../../util/shared'; import { AbstractAPI } from './AbstractApi'; - /** * @deprecated Switch to the public interstitial endpoint from Clerk Backend API. */ export class InterstitialAPI extends AbstractAPI { public async getInterstitial() { + deprecated( + 'getInterstitial()', + 'Switch to `Clerk(...).localInterstitial(...)` from `import { Clerk } from "@clerk/backend"`.', + ); + return this.request({ path: 'internal/interstitial', method: 'GET', From 5ba64b07cfa785394d82970aa8025f52f66e8620 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 17:29:13 +0300 Subject: [PATCH 05/11] chore(backend): Warn about picture/logoUrl/profileImageUrl (image related) deprecations --- packages/backend/src/api/resources/ExternalAccount.ts | 3 +++ packages/backend/src/api/resources/Organization.ts | 3 +++ packages/backend/src/api/resources/OrganizationMembership.ts | 3 +++ packages/backend/src/api/resources/User.ts | 3 +++ packages/backend/src/util/shared.ts | 1 + 5 files changed, 13 insertions(+) diff --git a/packages/backend/src/api/resources/ExternalAccount.ts b/packages/backend/src/api/resources/ExternalAccount.ts index 24de8f99a46..e1baa47b24d 100644 --- a/packages/backend/src/api/resources/ExternalAccount.ts +++ b/packages/backend/src/api/resources/ExternalAccount.ts @@ -1,3 +1,4 @@ +import { deprecatedProperty } from '../../util/shared'; import type { ExternalAccountJSON } from './JSON'; import { Verification } from './Verification'; @@ -41,3 +42,5 @@ export class ExternalAccount { ); } } + +deprecatedProperty(ExternalAccount, 'picture', 'Use `imageUrl` instead.'); diff --git a/packages/backend/src/api/resources/Organization.ts b/packages/backend/src/api/resources/Organization.ts index ac1dcdc7c1f..8766520f1e7 100644 --- a/packages/backend/src/api/resources/Organization.ts +++ b/packages/backend/src/api/resources/Organization.ts @@ -1,3 +1,4 @@ +import { deprecatedProperty } from '../../util/shared'; import type { OrganizationJSON } from './JSON'; export class Organization { @@ -40,3 +41,5 @@ export class Organization { ); } } + +deprecatedProperty(Organization, 'logoUrl', 'Use `imageUrl` instead.'); diff --git a/packages/backend/src/api/resources/OrganizationMembership.ts b/packages/backend/src/api/resources/OrganizationMembership.ts index a318bb4a9c0..d3b9ed0dd49 100644 --- a/packages/backend/src/api/resources/OrganizationMembership.ts +++ b/packages/backend/src/api/resources/OrganizationMembership.ts @@ -1,3 +1,4 @@ +import { deprecatedProperty } from '../../util/shared'; import { Organization } from '../resources'; import type { OrganizationMembershipRole } from './Enums'; import type { OrganizationMembershipJSON, OrganizationMembershipPublicUserDataJSON } from './JSON'; @@ -54,3 +55,5 @@ export class OrganizationMembershipPublicUserData { ); } } + +deprecatedProperty(OrganizationMembershipPublicUserData, 'profileImageUrl', 'Use `imageUrl` instead.'); diff --git a/packages/backend/src/api/resources/User.ts b/packages/backend/src/api/resources/User.ts index a3c5b4ea7b8..937cd170767 100644 --- a/packages/backend/src/api/resources/User.ts +++ b/packages/backend/src/api/resources/User.ts @@ -1,3 +1,4 @@ +import { deprecatedProperty } from '../../util/shared'; import { EmailAddress } from './EmailAddress'; import { ExternalAccount } from './ExternalAccount'; import type { ExternalAccountJSON, UserJSON } from './JSON'; @@ -72,3 +73,5 @@ export class User { ); } } + +deprecatedProperty(User, 'profileImageUrl', 'Use `imageUrl` instead.'); diff --git a/packages/backend/src/util/shared.ts b/packages/backend/src/util/shared.ts index 1a8d1b90711..de2bd9a6ae5 100644 --- a/packages/backend/src/util/shared.ts +++ b/packages/backend/src/util/shared.ts @@ -7,6 +7,7 @@ export { isProductionFromApiKey, parsePublishableKey, deprecated, + deprecatedProperty, } from '@clerk/shared'; import { buildErrorThrower } from '@clerk/shared'; From 7502f41f1562535bb2b264f2754a2a9c7e6ecdf4 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 17:33:33 +0300 Subject: [PATCH 06/11] chore(backend): Warn about pkgVersion deprecation --- packages/backend/src/tokens/interstitial.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/backend/src/tokens/interstitial.ts b/packages/backend/src/tokens/interstitial.ts index b6da5369326..64721a06db8 100644 --- a/packages/backend/src/tokens/interstitial.ts +++ b/packages/backend/src/tokens/interstitial.ts @@ -37,6 +37,9 @@ export function loadInterstitialFromLocal(options: Omit From 8e26d5338aed5007aba330e9b7ca624ab5f42e5b Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 18:57:03 +0300 Subject: [PATCH 07/11] chore(backend): Warn about clockSkewInSeconds deprecation --- packages/backend/src/tokens/jwt/verifyJwt.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/backend/src/tokens/jwt/verifyJwt.ts b/packages/backend/src/tokens/jwt/verifyJwt.ts index ca7bcec6e63..c22321f2606 100644 --- a/packages/backend/src/tokens/jwt/verifyJwt.ts +++ b/packages/backend/src/tokens/jwt/verifyJwt.ts @@ -4,6 +4,7 @@ import type { Jwt, JwtPayload } from '@clerk/types'; // For more information refer to https://sinonjs.org/how-to/stub-dependency/ import runtime from '../../runtime'; import { base64url } from '../../util/rfc4648'; +import { deprecated } from '../../util/shared'; import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../errors'; import type { IssuerResolver } from './assertions'; import { @@ -114,6 +115,10 @@ export async function verifyJwt( token: string, { audience, authorizedParties, clockSkewInSeconds, clockSkewInMs, issuer, key }: VerifyJwtOptions, ): Promise { + if (clockSkewInSeconds) { + deprecated('clockSkewInSeconds', 'Use `clockSkewInMs` instead.'); + } + const clockSkew = clockSkewInMs || clockSkewInSeconds || DEFAULT_CLOCK_SKEW_IN_SECONDS; const decoded = decodeJwt(token); From c35f85b7ca0ad1e8f703e6f4880e081681a6bbe4 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 19:41:34 +0300 Subject: [PATCH 08/11] chore(backend): Warn about backend api return format deprecation Currently the return value is the response.body `data` or throws a ClerkAPIResponseError error with the response.body `errors` --- packages/backend/src/api/request.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/backend/src/api/request.ts b/packages/backend/src/api/request.ts index fee69a39486..e7ed19bc0b9 100644 --- a/packages/backend/src/api/request.ts +++ b/packages/backend/src/api/request.ts @@ -51,6 +51,11 @@ type LegacyRequestFunction = (requestOptions: ClerkBackendApiRequestOptions) const withLegacyReturn = (cb: any): LegacyRequestFunction => async (...args) => { + deprecated( + '', + 'Resources return format will switch to `{ data: any, errors: ClerkAPIError[] }` from `data | never` the next major version.', + 'resources-legacy-return', + ); // @ts-ignore const { data, errors, status, statusText } = await cb(...args); if (errors === null) { From 01930859aee76732d0a29573b121dd55c2fc97be Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 25 Sep 2023 19:53:51 +0300 Subject: [PATCH 09/11] chore(backend): Add changeset for backend deprecation warnings --- .changeset/two-ads-type.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .changeset/two-ads-type.md diff --git a/.changeset/two-ads-type.md b/.changeset/two-ads-type.md new file mode 100644 index 00000000000..31491e30371 --- /dev/null +++ b/.changeset/two-ads-type.md @@ -0,0 +1,14 @@ +--- +"@clerk/backend": patch +--- + +Apply deprecation warnings backend package for: +- backend api return format +- `clockSkewInSeconds` +- `pkgVersion` +- `picture`/`logoUrl`/`profileImageUrl` +- `InterstitialAPI` +- `httpOptions` +- `apiKey` +- `frontendApi` +- `__unstable_options` From bdfbf0d9074f17d8bc29c939e45f8d3caa039274 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Thu, 28 Sep 2023 15:05:35 +0300 Subject: [PATCH 10/11] chore(backend): Warn about __unstable_options deprecation --- packages/backend/src/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index f7e28f3fb4b..9879546c9e3 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -1,3 +1,5 @@ +import { deprecatedObjectProperty } from '@clerk/shared'; + import type { CreateBackendApiOptions } from './api'; import { createBackendApiClient } from './api'; import type { CreateAuthenticateRequestOptions } from './tokens'; @@ -26,7 +28,7 @@ export function Clerk(options: ClerkOptions) { const apiClient = createBackendApiClient(opts); const requestState = createAuthenticateRequest({ options: opts, apiClient }); - return { + const clerkInstance = { ...apiClient, ...requestState, /** @@ -34,4 +36,14 @@ export function Clerk(options: ClerkOptions) { */ __unstable_options: opts, }; + + // The __unstable_options is not being used internally and + // it's only being set in packages/sdk-node/src/clerkClient.ts#L86 + deprecatedObjectProperty( + clerkInstance, + '__unstable_options', + 'Use `createClerkClient({...})` to create a new clerk instance instead.', + ); + + return clerkInstance; } From d9ef2a6747988226bfa4959fb317128f943a2f00 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Thu, 28 Sep 2023 15:35:56 +0300 Subject: [PATCH 11/11] fix(repo): Make changeset entries for deprecation warnings consistent --- .changeset/eighty-swans-trade.md | 2 +- .changeset/late-carrots-notice.md | 4 ++-- .changeset/silent-fishes-change.md | 2 +- .changeset/spicy-toys-change.md | 7 ++++++- .changeset/two-ads-type.md | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.changeset/eighty-swans-trade.md b/.changeset/eighty-swans-trade.md index addb3926466..cd5cd110725 100644 --- a/.changeset/eighty-swans-trade.md +++ b/.changeset/eighty-swans-trade.md @@ -2,7 +2,7 @@ '@clerk/shared': patch --- -Apply deprecation warnings: +Apply deprecation warnings for `@clerk/shared`: - `OrganizationContext` - `organizationList` - `useOrganizations` diff --git a/.changeset/late-carrots-notice.md b/.changeset/late-carrots-notice.md index a051c9607da..a0c75d9d571 100644 --- a/.changeset/late-carrots-notice.md +++ b/.changeset/late-carrots-notice.md @@ -1,5 +1,5 @@ --- '@clerk/clerk-react': patch --- - -Warn about `setSession` deprecation. +Apply deprecation warnings for `@clerk/clerk-react`: +- `setSession` diff --git a/.changeset/silent-fishes-change.md b/.changeset/silent-fishes-change.md index ed10e1ea9b4..172c0e2c479 100644 --- a/.changeset/silent-fishes-change.md +++ b/.changeset/silent-fishes-change.md @@ -2,4 +2,4 @@ '@clerk/backend': minor --- -Replace utilities with @clerk/shared exports +Replace utilities with `@clerk/shared` exports diff --git a/.changeset/spicy-toys-change.md b/.changeset/spicy-toys-change.md index e79bd7a4cb4..c3a0649afb5 100644 --- a/.changeset/spicy-toys-change.md +++ b/.changeset/spicy-toys-change.md @@ -2,4 +2,9 @@ '@clerk/nextjs': patch --- -Warn about deprecations that will be dropped in next major version +Apply deprecation warnings for `@clerk/nextjs`: +- `CLERK_JS_VERSION` environment variable +- `CLERK_API_KEY` environment variable +- `NEXT_PUBLIC_CLERK_FRONTEND_API` environment variable +- `withClerkMiddleware` +- `withServerSideAuth` \ No newline at end of file diff --git a/.changeset/two-ads-type.md b/.changeset/two-ads-type.md index 31491e30371..e2500803378 100644 --- a/.changeset/two-ads-type.md +++ b/.changeset/two-ads-type.md @@ -2,7 +2,7 @@ "@clerk/backend": patch --- -Apply deprecation warnings backend package for: +Apply deprecation warnings for `@clerk/backend`: - backend api return format - `clockSkewInSeconds` - `pkgVersion`