Skip to content

Commit 12aa662

Browse files
committed
feat(vue,astro): support ui versioning
1 parent 8eaa0f3 commit 12aa662

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

packages/astro/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"nanostores": "1.0.1"
9595
},
9696
"devDependencies": {
97+
"@clerk/ui": "workspace:^",
9798
"astro": "^5.15.3"
9899
},
99100
"peerDependencies": {

packages/astro/src/internal/create-clerk-instance.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@clerk/shared/loadClerkJsScript';
66
import type { ClerkOptions } from '@clerk/shared/types';
77
import type { ClerkUiConstructor } from '@clerk/shared/ui';
8+
import type { Ui } from '@clerk/ui/internal';
89

910
import { $clerkStore } from '../stores/external';
1011
import { $clerk, $csrState } from '../stores/internal';
@@ -34,7 +35,7 @@ function createNavigationHandler(
3435
*/
3536
const createClerkInstance = runOnce(createClerkInstanceInternal);
3637

37-
async function createClerkInstanceInternal(options?: AstroClerkCreateInstanceParams) {
38+
async function createClerkInstanceInternal<TUi extends Ui = Ui>(options?: AstroClerkCreateInstanceParams<TUi>) {
3839
let clerkJSInstance = window.Clerk;
3940
let clerkUiCtor: Promise<ClerkUiConstructor> | undefined;
4041

@@ -63,16 +64,18 @@ async function createClerkInstanceInternal(options?: AstroClerkCreateInstancePar
6364
$clerk.set(clerkJSInstance);
6465
}
6566

66-
initOptions = {
67+
const clerkOptions = {
6768
routerPush: createNavigationHandler(window.history.pushState.bind(window.history)),
6869
routerReplace: createNavigationHandler(window.history.replaceState.bind(window.history)),
6970
...options,
7071
// Pass the clerk-ui constructor promise to clerk.load()
7172
clerkUiCtor,
72-
};
73+
} as unknown as ClerkOptions;
74+
75+
initOptions = clerkOptions;
7376

7477
return clerkJSInstance
75-
.load(initOptions)
78+
.load(clerkOptions)
7679
.then(() => {
7780
$csrState.setKey('isLoaded', true);
7881
// Notify subscribers that $clerkStore has been loaded.
@@ -94,16 +97,17 @@ async function createClerkInstanceInternal(options?: AstroClerkCreateInstancePar
9497
.catch(() => {});
9598
}
9699

97-
function updateClerkOptions(options: AstroClerkUpdateOptions) {
100+
function updateClerkOptions<TUi extends Ui = Ui>(options: AstroClerkUpdateOptions<TUi>) {
98101
const clerk = $clerk.get();
99102
if (!clerk) {
100103
throw new Error('Missing clerk instance');
101104
}
102-
// `__unstable__updateProps` is not exposed as public API from `@clerk/types`
103-
void (clerk as any).__unstable__updateProps({
105+
const updateOptions = {
104106
options: { ...initOptions, ...options },
105107
appearance: { ...initOptions?.appearance, ...options.appearance },
106-
});
108+
} as unknown as { options: ClerkOptions; appearance?: any };
109+
// `__unstable__updateProps` is not exposed as public API from `@clerk/types`
110+
void (clerk as any).__unstable__updateProps(updateOptions);
107111
}
108112

109113
export { createClerkInstance, updateClerkOptions };

packages/astro/src/types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import type {
77
Without,
88
} from '@clerk/shared/types';
99
import type { ClerkUiConstructor } from '@clerk/shared/ui';
10+
import type { Appearance, Ui } from '@clerk/ui/internal';
1011

11-
type AstroClerkUpdateOptions = Pick<ClerkOptions, 'appearance' | 'localization'>;
12+
type AstroClerkUpdateOptions<TUi extends Ui = Ui> = Pick<ClerkOptions, 'localization'> & {
13+
appearance?: Appearance<TUi>;
14+
};
1215

13-
type AstroClerkIntegrationParams = Without<
16+
type AstroClerkIntegrationParams<TUi extends Ui = Ui> = Without<
1417
ClerkOptions,
1518
| 'isSatellite'
1619
| 'sdkMetadata'
@@ -21,8 +24,10 @@ type AstroClerkIntegrationParams = Without<
2124
| 'routerPush'
2225
| 'polling'
2326
| 'touchSession'
27+
| 'appearance'
2428
> &
2529
MultiDomainAndOrProxyPrimitives & {
30+
appearance?: Appearance<TUi>;
2631
clerkJSUrl?: string;
2732
clerkJSVariant?: 'headless' | '';
2833
clerkJSVersion?: string;
@@ -32,7 +37,9 @@ type AstroClerkIntegrationParams = Without<
3237
clerkUiUrl?: string;
3338
};
3439

35-
type AstroClerkCreateInstanceParams = AstroClerkIntegrationParams & { publishableKey: string };
40+
type AstroClerkCreateInstanceParams<TUi extends Ui = Ui> = AstroClerkIntegrationParams<TUi> & {
41+
publishableKey: string;
42+
};
3643

3744
// Copied from `@clerk/react`
3845
export interface HeadlessBrowserClerk extends Clerk {

packages/vue/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"@clerk/shared": "workspace:^"
6767
},
6868
"devDependencies": {
69+
"@clerk/ui": "workspace:^",
6970
"@testing-library/vue": "^8.1.0",
7071
"@vitejs/plugin-vue": "^5.2.4",
7172
"@vue.ts/tsx-auto-props": "^0.6.0",

packages/vue/src/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { loadClerkJsScript, type LoadClerkJsScriptOptions, loadClerkUiScript } f
44
import type {
55
Clerk,
66
ClientResource,
7+
ClerkOptions,
78
InitialState,
89
IsomorphicClerkOptions,
910
MultiDomainAndOrProxy,
1011
Resources,
1112
Without,
1213
} from '@clerk/shared/types';
1314
import type { ClerkUiConstructor } from '@clerk/shared/ui';
15+
import type { Appearance, Ui } from '@clerk/ui/internal';
1416
import type { Plugin } from 'vue';
1517
import { computed, ref, shallowRef, triggerRef } from 'vue';
1618

@@ -22,9 +24,10 @@ declare global {
2224
}
2325
}
2426

25-
export type PluginOptions = Without<IsomorphicClerkOptions, 'domain' | 'proxyUrl'> &
27+
export type PluginOptions<TUi extends Ui = Ui> = Without<IsomorphicClerkOptions, 'domain' | 'proxyUrl' | 'appearance'> &
2628
MultiDomainAndOrProxy & {
2729
initialState?: InitialState;
30+
appearance?: Appearance<TUi>;
2831
};
2932

3033
const SDK_METADATA = {
@@ -52,7 +55,7 @@ const SDK_METADATA = {
5255
* ```
5356
*/
5457
export const clerkPlugin: Plugin<[PluginOptions]> = {
55-
install(app, pluginOptions) {
58+
install<TUi extends Ui = Ui>(app: any, pluginOptions: PluginOptions<TUi>) {
5659
const { initialState } = pluginOptions || {};
5760

5861
const loaded = shallowRef(false);
@@ -93,7 +96,8 @@ export const clerkPlugin: Plugin<[PluginOptions]> = {
9396
}
9497

9598
clerk.value = window.Clerk;
96-
await window.Clerk.load({ ...options, clerkUiCtor: clerkUiCtorPromise });
99+
const loadOptions = { ...options, clerkUiCtor: clerkUiCtorPromise } as unknown as ClerkOptions;
100+
await window.Clerk.load(loadOptions);
97101
loaded.value = true;
98102

99103
if (clerk.value) {
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { ClerkOptions } from '@clerk/shared/types';
2+
import type { Appearance, Ui } from '@clerk/ui/internal';
23

3-
type ClerkUpdateOptions = Pick<ClerkOptions, 'appearance' | 'localization'>;
4+
type ClerkUpdateOptions<TUi extends Ui = Ui> = Pick<ClerkOptions, 'localization'> & {
5+
appearance?: Appearance<TUi>;
6+
};
47

58
/**
69
* Updates Clerk's options at runtime.
@@ -9,23 +12,25 @@ type ClerkUpdateOptions = Pick<ClerkOptions, 'appearance' | 'localization'>;
912
*
1013
* @example
1114
* import { frFR } from '@clerk/localizations';
12-
* import { dark } from '@clerk/themes';
15+
* import { dark } from '@clerk/ui/themes';
1316
*
1417
* updateClerkOptions({
1518
* appearance: { baseTheme: dark },
1619
* localization: frFR
1720
* });
1821
*/
19-
export function updateClerkOptions(options: ClerkUpdateOptions) {
22+
export function updateClerkOptions<TUi extends Ui = Ui>(options: ClerkUpdateOptions<TUi>) {
2023
if (!window.Clerk) {
2124
throw new Error('Missing Clerk instance');
2225
}
2326

24-
// @ts-expect-error - `__unstable__updateProps` is not exposed as public API from `@clerk/types`
25-
void window.Clerk.__unstable__updateProps({
27+
const updateOptions = {
2628
options: {
2729
localization: options.localization,
2830
},
2931
appearance: options.appearance,
30-
});
32+
} as unknown as { options: any; appearance?: any };
33+
34+
// @ts-expect-error - `__unstable__updateProps` is not exposed as public API from `@clerk/types`
35+
void window.Clerk.__unstable__updateProps(updateOptions);
3136
}

0 commit comments

Comments
 (0)