Skip to content

Commit

Permalink
chore(backend): Drop loadInterstitialFromBAPI & `buildPublicInterst…
Browse files Browse the repository at this point in the history
…itialUrl` (#2148)
  • Loading branch information
dimkl authored Nov 16, 2023
1 parent 0976d03 commit 8b5c81b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 120 deletions.
2 changes: 2 additions & 0 deletions .changeset/real-cougars-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion .changeset/silly-poems-tease.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Drop deprecated properties. Migration steps:
- `OrganizationMembershipPublicUserData.profileImageUrl`
- `OrganizationMembershipPublicUserDataJSON.profile_image_url`
- drop `pkgVersion`
- use `Organization.getOrganizationInvitationList` with // TODO
- use `Organization.getOrganizationInvitationList` with `status` instead of `getPendingOrganizationInvitationList`
- drop `orgs` claim (if required, can be manually added by using `user.organizations` in a jwt template)
- use `localInterstitial` instead of `remotePublicInterstitial` / `remotePublicInterstitialUrl`

Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/tokens/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ApiClient } from '../api';
import { API_URL, API_VERSION } from '../constants';
import type { LoadInterstitialOptions } from './interstitial';
import { buildPublicInterstitialUrl, loadInterstitialFromBAPI, loadInterstitialFromLocal } from './interstitial';
import { loadInterstitialFromLocal } from './interstitial';
import type { AuthenticateRequestOptions } from './request';
import { authenticateRequest as authenticateRequestOriginal, debugRequestState } from './request';

Expand Down Expand Up @@ -36,7 +36,7 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio
isSatellite: buildtimeIsSatellite = false,
domain: buildtimeDomain = '',
audience: buildtimeAudience = '',
userAgent: buildUserAgent,
userAgent: buildtimeUserAgent,
} = params.options;

const authenticateRequest = ({
Expand All @@ -47,7 +47,8 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio
jwtKey: runtimeJwtKey,
isSatellite: runtimeIsSatellite,
domain: runtimeDomain,
searchParams,
searchParams: runtimeSearchParams,
userAgent: runtimeUserAgent,
...rest
}: Omit<AuthenticateRequestOptions, 'apiUrl' | 'apiVersion'>) => {
return authenticateRequestOriginal({
Expand All @@ -61,7 +62,8 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio
isSatellite: runtimeIsSatellite || buildtimeIsSatellite,
domain: runtimeDomain || buildtimeDomain,
jwtKey: runtimeJwtKey || buildtimeJwtKey,
searchParams,
searchParams: runtimeSearchParams,
userAgent: runtimeUserAgent?.toString() || buildtimeUserAgent,
});
};

Expand Down
46 changes: 0 additions & 46 deletions packages/backend/src/tokens/interstitial.test.ts

This file was deleted.

68 changes: 1 addition & 67 deletions packages/backend/src/tokens/interstitial.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import type { MultiDomainAndOrProxyPrimitives } from '@clerk/types';

import { API_VERSION, USER_AGENT } from '../constants';
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
// For more information refer to https://sinonjs.org/how-to/stub-dependency/
import runtime from '../runtime';
import { joinPaths } from '../util/path';
import {
addClerkPrefix,
callWithRetry,
getClerkJsMajorVersionOrTag,
getScriptUrl,
isDevOrStagingUrl,
parsePublishableKey,
} from '../util/shared';
import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from './errors';
import { addClerkPrefix, getScriptUrl, isDevOrStagingUrl, parsePublishableKey } from '../util/shared';
import type { DebugRequestSate } from './request';

export type LoadInterstitialOptions = {
Expand Down Expand Up @@ -114,58 +103,3 @@ export function loadInterstitialFromLocal(options: Omit<LoadInterstitialOptions,
</body>
`;
}

// TODO: Add caching to Interstitial
export async function loadInterstitialFromBAPI(options: LoadInterstitialOptions) {
const url = buildPublicInterstitialUrl(options);
const response = await callWithRetry(() =>
runtime.fetch(buildPublicInterstitialUrl(options), {
method: 'GET',
headers: {
'Clerk-Backend-SDK': options.userAgent || USER_AGENT,
},
}),
);

if (!response.ok) {
throw new TokenVerificationError({
action: TokenVerificationErrorAction.ContactSupport,
message: `Error loading Clerk Interstitial from ${url} with code=${response.status}`,
reason: TokenVerificationErrorReason.RemoteInterstitialFailedToLoad,
});
}

return response.text();
}

export function buildPublicInterstitialUrl(options: LoadInterstitialOptions) {
const frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || '';
const { apiUrl, clerkJSVersion, publishableKey, proxyUrl, isSatellite, domain, signInUrl } = options;
const url = new URL(apiUrl);
url.pathname = joinPaths(url.pathname, API_VERSION, '/public/interstitial');

url.searchParams.append('clerk_js_version', clerkJSVersion || getClerkJsMajorVersionOrTag(frontendApi));
if (publishableKey) {
url.searchParams.append('publishable_key', publishableKey);
}

if (proxyUrl) {
url.searchParams.append('proxy_url', proxyUrl);
}

if (isSatellite) {
url.searchParams.append('is_satellite', 'true');
}

url.searchParams.append('sign_in_url', signInUrl || '');

if (!isDevOrStagingUrl(frontendApi)) {
url.searchParams.append('use_domain_for_script', 'true');
}

if (domain) {
url.searchParams.append('domain', domain);
}

return url.href;
}
2 changes: 0 additions & 2 deletions packages/backend/tests/suites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import factoryTest from './dist/api/factory.test.js';
import exportsTest from './dist/exports.test.js';
import redirectTest from './dist/redirections.test.js';
import authObjectsTest from './dist/tokens/authObjects.test.js';
import interstitialRequestTest from './dist/tokens/interstitial.test.js';
import jwtAssertionsTest from './dist/tokens/jwt/assertions.test.js';
import cryptoKeysTest from './dist/tokens/jwt/cryptoKeys.test.js';
import signJwtTest from './dist/tokens/jwt/signJwt.test.js';
Expand Down Expand Up @@ -34,7 +33,6 @@ const suites = [
factoryTest,
redirectTest,
utilsTest,
interstitialRequestTest,
];

export default suites;

0 comments on commit 8b5c81b

Please sign in to comment.