Skip to content

feat(clerk-js,clerk-react,types): Expose fapi version #6434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/hip-ideas-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
---

Expose the frontend api version the clerk instance is using via `Clerk.apiVersion`.
21 changes: 20 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ import { memoizeListenerCallback } from '../utils/memoizeStateListenerCallback';
import { RedirectUrls } from '../utils/redirectUrls';
import { AuthCookieService } from './auth/AuthCookieService';
import { CaptchaHeartbeat } from './auth/CaptchaHeartbeat';
import { CLERK_SATELLITE_URL, CLERK_SUFFIXED_COOKIES, CLERK_SYNCED, ERROR_CODES } from './constants';
import {
CLERK_SATELLITE_URL,
CLERK_SUFFIXED_COOKIES,
CLERK_SYNCED,
ERROR_CODES,
SUPPORTED_FAPI_VERSION,
} from './constants';
import {
clerkErrorInitFailed,
clerkInvalidSignInUrlFormat,
Expand Down Expand Up @@ -275,6 +281,19 @@ export class Clerk implements ClerkInterface {
return Clerk.sdkMetadata;
}

debug() {
return {
info: Object.freeze({
version: this.version,
frontendApi: Object.freeze({
version: SUPPORTED_FAPI_VERSION,
host: this.frontendApi,
}),
loadedOptions: { ...this.#options },
}),
};
}

get loaded(): boolean {
return this.status === 'degraded' || this.status === 'ready';
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ type IsomorphicLoadedClerk = Without<
| '__internal_reloadInitialResources'
| 'billing'
| 'apiKeys'
| 'debug'
| '__internal_setComponentNavigationContext'
| '__internal_setActiveInProgress'
| '__internal_hasAfterAuthFlows'
> & {
client: ClientResource | undefined;
billing: CommerceBillingNamespace | undefined;
apiKeys: APIKeysNamespace | undefined;
debug: ReturnType<LoadedClerk['debug']>;
};

export class IsomorphicClerk implements IsomorphicLoadedClerk {
Expand Down Expand Up @@ -652,6 +654,10 @@ export class IsomorphicClerk implements IsomorphicLoadedClerk {
return this.clerkjs?.version;
}

get debug() {
return this.clerkjs?.debug?.() as ReturnType<LoadedClerk['debug']>;
}

get client(): ClientResource | undefined {
if (this.clerkjs) {
return this.clerkjs.client;
Expand Down
14 changes: 14 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@
*/
sdkMetadata: SDKMetadata | undefined;

/**
* Returns a snapshot of data through the `info` property. It can be used during debugging sessions.
*/
debug: () => {
info: {
version: string;
frontendApi: {
version: string;
host: string;
};
loadedOptions?: ClerkOptions;
};
};

/**
* If true the bootstrapping of Clerk.load() has completed successfully.
*/
Expand Down Expand Up @@ -1138,7 +1152,7 @@
*/
windowNavigate: (to: URL | string) => void;
},
) => Promise<unknown> | unknown;

Check warning on line 1155 in packages/types/src/clerk.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'unknown' overrides all other types in this union type

export type WithoutRouting<T> = Omit<T, 'path' | 'routing'>;

Expand Down
Loading