From 07a2dd54adfa557256fc1727b99d6f8c623680e4 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 16 Oct 2023 20:50:31 +0300 Subject: [PATCH 01/15] chore(backend): Drop `__unstable_options` --- packages/backend/src/index.ts | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 0d1a552ca2e..10b6e9538be 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -1,5 +1,3 @@ -import { deprecatedObjectProperty } from '@clerk/shared/deprecated'; - import type { CreateBackendApiOptions } from './api'; import { createBackendApiClient } from './api'; import type { CreateAuthenticateRequestOptions } from './tokens'; @@ -28,22 +26,8 @@ export function Clerk(options: ClerkOptions) { const apiClient = createBackendApiClient(opts); const requestState = createAuthenticateRequest({ options: opts, apiClient }); - const clerkInstance = { + return { ...apiClient, ...requestState, - /** - * @deprecated This prop has been deprecated and will be removed in the next major release. - */ - __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 cc90167ccf5ebcce6768a355a4fe69e33cad3911 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Mon, 16 Oct 2023 23:55:01 +0300 Subject: [PATCH 02/15] chore(backend): Drop `frontendApi` --- packages/backend/src/redirections.test.ts | 82 +------------------ packages/backend/src/redirections.ts | 13 +-- packages/backend/src/tokens/authStatus.ts | 36 ++------ packages/backend/src/tokens/factory.ts | 8 -- .../backend/src/tokens/interstitial.test.ts | 1 - packages/backend/src/tokens/interstitial.ts | 36 ++------ packages/backend/src/tokens/request.test.ts | 15 ++-- packages/backend/src/tokens/request.ts | 15 +--- 8 files changed, 25 insertions(+), 181 deletions(-) diff --git a/packages/backend/src/redirections.test.ts b/packages/backend/src/redirections.test.ts index 4038409a965..0085781c7fe 100644 --- a/packages/backend/src/redirections.test.ts +++ b/packages/backend/src/redirections.test.ts @@ -68,7 +68,7 @@ export default (QUnit: QUnit) => { assert.ok(redirectAdapterSpy.calledWith(`http://signin.url:3001/sign-in?redirect_url=${encodedUrl}`)); }); - test('raises error without signInUrl and frontendApi/publishableKey in redirectToSignIn', assert => { + test('raises error without signInUrl and publishableKey in redirectToSignIn', assert => { const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); const { redirectToSignIn } = redirect({ redirectAdapter: redirectAdapterSpy }); @@ -80,45 +80,6 @@ export default (QUnit: QUnit) => { ); }); - test('returns path based url with development frontendApi but without signInUrl to redirectToSignIn', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignIn } = redirect({ - redirectAdapter: redirectAdapterSpy, - frontendApi: 'clerk.included.katydid-92.lcl.dev', - }); - - const result = redirectToSignIn({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok( - redirectAdapterSpy.calledWith( - `https://accounts.included.katydid-92.lcl.dev/sign-in?redirect_url=${encodedUrl}`, - ), - ); - }); - - test('returns path based url with production frontendApi but without signInUrl to redirectToSignIn', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignIn } = redirect({ redirectAdapter: redirectAdapterSpy, frontendApi: 'clerk.example.com' }); - - const result = redirectToSignIn({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok(redirectAdapterSpy.calledWith(`https://accounts.example.com/sign-in?redirect_url=${encodedUrl}`)); - }); - - test('returns path based url with development (kima) frontendApi but without signInUrl to redirectToSignIn', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignIn } = redirect({ - redirectAdapter: redirectAdapterSpy, - frontendApi: 'included.katydid-92.clerk.accounts.dev', - }); - - const result = redirectToSignIn({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok( - redirectAdapterSpy.calledWith(`https://included.katydid-92.accounts.dev/sign-in?redirect_url=${encodedUrl}`), - ); - }); - test('returns path based url with development publishableKey but without signInUrl to redirectToSignIn', assert => { const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); const { redirectToSignIn } = redirect({ @@ -214,7 +175,7 @@ export default (QUnit: QUnit) => { assert.ok(redirectAdapterSpy.calledWith(`http://signup.url:3001/sign-up?redirect_url=${encodedUrl}`)); }); - test('raises error without signUpUrl and frontendApi/publishableKey in redirectToSignUp', assert => { + test('raises error without signUpUrl and publishableKey in redirectToSignUp', assert => { const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); const { redirectToSignUp } = redirect({ redirectAdapter: redirectAdapterSpy }); @@ -226,45 +187,6 @@ export default (QUnit: QUnit) => { ); }); - test('returns path based url with development frontendApi but without signUpUrl to redirectToSignUp', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignUp } = redirect({ - redirectAdapter: redirectAdapterSpy, - frontendApi: 'clerk.included.katydid-92.lcl.dev', - }); - - const result = redirectToSignUp({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok( - redirectAdapterSpy.calledWith( - `https://accounts.included.katydid-92.lcl.dev/sign-up?redirect_url=${encodedUrl}`, - ), - ); - }); - - test('returns path based url with production frontendApi but without signUpUrl to redirectToSignUp', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignUp } = redirect({ redirectAdapter: redirectAdapterSpy, frontendApi: 'clerk.example.com' }); - - const result = redirectToSignUp({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok(redirectAdapterSpy.calledWith(`https://accounts.example.com/sign-up?redirect_url=${encodedUrl}`)); - }); - - test('returns path based url with development (kima) frontendApi but without signUpUrl to redirectToSignUp', assert => { - const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); - const { redirectToSignUp } = redirect({ - redirectAdapter: redirectAdapterSpy, - frontendApi: 'included.katydid-92.clerk.accounts.dev', - }); - - const result = redirectToSignUp({ returnBackUrl }); - assert.equal(result, 'redirectAdapterValue'); - assert.ok( - redirectAdapterSpy.calledWith(`https://included.katydid-92.accounts.dev/sign-up?redirect_url=${encodedUrl}`), - ); - }); - test('returns path based url with development publishableKey but without signUpUrl to redirectToSignUp', assert => { const redirectAdapterSpy = sinon.spy(_url => 'redirectAdapterValue'); const { redirectToSignUp } = redirect({ diff --git a/packages/backend/src/redirections.ts b/packages/backend/src/redirections.ts index 7a6f2dbcaf2..ce26dec7dab 100644 --- a/packages/backend/src/redirections.ts +++ b/packages/backend/src/redirections.ts @@ -30,19 +30,10 @@ type RedirectParams = { signInUrl?: string; signUpUrl?: string; publishableKey?: string; - /** - * @deprecated Use `publishableKey` instead. - */ - frontendApi?: string; }; -export function redirect({ redirectAdapter, signUpUrl, signInUrl, frontendApi, publishableKey }: RedirectParams) { - if (!frontendApi) { - frontendApi = parsePublishableKey(publishableKey)?.frontendApi; - } else { - deprecated('frontendApi', 'Use `publishableKey` instead.'); - } - +export function redirect({ redirectAdapter, signUpUrl, signInUrl, publishableKey }: RedirectParams) { + const frontendApi = parsePublishableKey(publishableKey)?.frontendApi; const accountsBaseUrl = buildAccountsBaseUrl(frontendApi); const redirectToSignUp = ({ returnBackUrl }: SignUpParams = {}) => { diff --git a/packages/backend/src/tokens/authStatus.ts b/packages/backend/src/tokens/authStatus.ts index 953a028d419..f625222eebf 100644 --- a/packages/backend/src/tokens/authStatus.ts +++ b/packages/backend/src/tokens/authStatus.ts @@ -16,7 +16,6 @@ export type SignedInState = { status: AuthStatus.SignedIn; reason: null; message: null; - frontendApi: string; proxyUrl?: string; publishableKey: string; isSatellite: boolean; @@ -35,7 +34,6 @@ export type SignedOutState = { status: AuthStatus.SignedOut; message: string; reason: AuthReason; - frontendApi: string; proxyUrl?: string; publishableKey: string; isSatellite: boolean; @@ -90,7 +88,6 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis apiUrl, apiVersion, cookieToken, - frontendApi, proxyUrl, publishableKey, domain, @@ -146,7 +143,6 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis status: AuthStatus.SignedIn, reason: null, message: null, - frontendApi, proxyUrl, publishableKey, domain, @@ -163,23 +159,13 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis } export function signedOut(options: T, reason: AuthReason, message = ''): SignedOutState { - const { - frontendApi, - publishableKey, - proxyUrl, - isSatellite, - domain, - signInUrl, - signUpUrl, - afterSignInUrl, - afterSignUpUrl, - } = options as any; + const { publishableKey, proxyUrl, isSatellite, domain, signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = + options as any; return { status: AuthStatus.SignedOut, reason, message, - frontendApi, proxyUrl, publishableKey, isSatellite, @@ -196,22 +182,12 @@ export function signedOut(options: T, reason: AuthReason, message = ''): Sign } export function interstitial(options: T, reason: AuthReason, message = ''): InterstitialState { - const { - frontendApi, - publishableKey, - proxyUrl, - isSatellite, - domain, - signInUrl, - signUpUrl, - afterSignInUrl, - afterSignUpUrl, - } = options as any; + const { publishableKey, proxyUrl, isSatellite, domain, signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = + options as any; return { status: AuthStatus.Interstitial, reason, message, - frontendApi, publishableKey, isSatellite, domain, @@ -228,13 +204,11 @@ export function interstitial(options: T, reason: AuthReason, message = ''): I } export function unknownState(options: T, reason: AuthReason, message = ''): UnknownState { - const { frontendApi, publishableKey, isSatellite, domain, signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = - options as any; + const { publishableKey, isSatellite, domain, signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = options as any; return { status: AuthStatus.Unknown, reason, message, - frontendApi, publishableKey, isSatellite, domain, diff --git a/packages/backend/src/tokens/factory.ts b/packages/backend/src/tokens/factory.ts index a3a640c276f..84a13573dc2 100644 --- a/packages/backend/src/tokens/factory.ts +++ b/packages/backend/src/tokens/factory.ts @@ -14,7 +14,6 @@ export type CreateAuthenticateRequestOptions = { | 'secretKey' | 'apiUrl' | 'apiVersion' - | 'frontendApi' | 'publishableKey' | 'jwtKey' | 'proxyUrl' @@ -34,7 +33,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio jwtKey: buildtimeJwtKey = '', apiUrl = API_URL, apiVersion = API_VERSION, - frontendApi: buildtimeFrontendApi = '', proxyUrl: buildProxyUrl = '', publishableKey: buildtimePublishableKey = '', isSatellite: buildtimeIsSatellite = false, @@ -47,7 +45,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio apiKey: runtimeApiKey, secretKey: runtimeSecretKey, audience: runtimeAudience, - frontendApi: runtimeFrontendApi, proxyUrl: runtimeProxyUrl, publishableKey: runtimePublishableKey, jwtKey: runtimeJwtKey, @@ -63,7 +60,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio audience: runtimeAudience || buildtimeAudience, apiUrl, apiVersion, - frontendApi: runtimeFrontendApi || buildtimeFrontendApi, proxyUrl: runtimeProxyUrl || buildProxyUrl, publishableKey: runtimePublishableKey || buildtimePublishableKey, isSatellite: runtimeIsSatellite || buildtimeIsSatellite, @@ -74,7 +70,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio }; const localInterstitial = ({ - frontendApi: runtimeFrontendApi, publishableKey: runtimePublishableKey, proxyUrl: runtimeProxyUrl, isSatellite: runtimeIsSatellite, @@ -83,7 +78,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio }: Omit) => loadInterstitialFromLocal({ ...rest, - frontendApi: runtimeFrontendApi || buildtimeFrontendApi, proxyUrl: runtimeProxyUrl || buildProxyUrl, publishableKey: runtimePublishableKey || buildtimePublishableKey, isSatellite: runtimeIsSatellite || buildtimeIsSatellite, @@ -91,7 +85,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio }); const remotePublicInterstitial = ({ - frontendApi: runtimeFrontendApi, publishableKey: runtimePublishableKey, proxyUrl: runtimeProxyUrl, isSatellite: runtimeIsSatellite, @@ -102,7 +95,6 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio return loadInterstitialFromBAPI({ ...rest, apiUrl, - frontendApi: runtimeFrontendApi || buildtimeFrontendApi, publishableKey: runtimePublishableKey || buildtimePublishableKey, proxyUrl: runtimeProxyUrl || buildProxyUrl, isSatellite: runtimeIsSatellite || buildtimeIsSatellite, diff --git a/packages/backend/src/tokens/interstitial.test.ts b/packages/backend/src/tokens/interstitial.test.ts index ab07be5da88..a27b3da1b1f 100644 --- a/packages/backend/src/tokens/interstitial.test.ts +++ b/packages/backend/src/tokens/interstitial.test.ts @@ -26,7 +26,6 @@ export default (QUnit: QUnit) => { const resp = await loadInterstitialFromBAPI({ apiUrl: 'https://api.clerk.test', publishableKey, - frontendApi: 'accounts.included.katydid-92.lcl.dev', userAgent: 'clerk-backend-sdk-from-options', }); diff --git a/packages/backend/src/tokens/interstitial.ts b/packages/backend/src/tokens/interstitial.ts index 31db9e6b274..ee0c6a70cec 100644 --- a/packages/backend/src/tokens/interstitial.ts +++ b/packages/backend/src/tokens/interstitial.ts @@ -19,7 +19,6 @@ import type { DebugRequestSate } from './request'; export type LoadInterstitialOptions = { apiUrl: string; - frontendApi: string; publishableKey: string; clerkJSUrl?: string; clerkJSVersion?: string; @@ -34,18 +33,14 @@ export type LoadInterstitialOptions = { } & MultiDomainAndOrProxyPrimitives; export function loadInterstitialFromLocal(options: Omit) { - if (options.frontendApi) { - deprecated('frontendApi', 'Use `publishableKey` instead.'); - } if (options.pkgVersion) { deprecated('pkgVersion', 'Use `clerkJSVersion` instead.'); } - options.frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi || ''; - const domainOnlyInProd = !isDevOrStagingUrl(options.frontendApi) ? addClerkPrefix(options.domain) : ''; + const frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || ''; + const domainOnlyInProd = !isDevOrStagingUrl(frontendApi) ? addClerkPrefix(options.domain) : ''; const { debugData, - frontendApi, pkgVersion, clerkJSUrl, clerkJSVersion, @@ -68,7 +63,6 @@ export function loadInterstitialFromLocal(options: Omit