@@ -2,15 +2,15 @@ import { buildErrorThrower, ClerkRuntimeError } from './error';
22import { createDevOrStagingUrlCache , parsePublishableKey } from './keys' ;
33import { loadScript } from './loadScript' ;
44import { isValidProxyUrl , proxyUrlToAbsoluteURL } from './proxy' ;
5- import type { ClerkOptions , SDKMetadata , Without } from './types' ;
5+ import type { SDKMetadata } from './types' ;
66import { addClerkPrefix } from './url' ;
77import { versionSelector } from './versionSelector' ;
88
99const { isDevOrStagingUrl } = createDevOrStagingUrlCache ( ) ;
1010
1111const errorThrower = buildErrorThrower ( { packageName : '@clerk/shared' } ) ;
1212
13- export type LoadClerkJsScriptOptions = Without < ClerkOptions , 'isSatellite' > & {
13+ export type LoadClerkJsScriptOptions = {
1414 publishableKey : string ;
1515 clerkJSUrl ?: string ;
1616 clerkJSVariant ?: 'headless' | '' ;
@@ -27,7 +27,7 @@ export type LoadClerkJsScriptOptions = Without<ClerkOptions, 'isSatellite'> & {
2727 scriptLoadTimeout ?: number ;
2828} ;
2929
30- export type LoadClerkUiScriptOptions = Without < ClerkOptions , 'isSatellite' > & {
30+ export type LoadClerkUiScriptOptions = {
3131 publishableKey : string ;
3232 clerkUiUrl ?: string ;
3333 proxyUrl ?: string ;
@@ -104,7 +104,7 @@ export const loadClerkJsScript = async (opts?: LoadClerkJsScriptOptions): Promis
104104 async : true ,
105105 crossOrigin : 'anonymous' ,
106106 nonce : opts . nonce ,
107- beforeLoad : applyClerkJsScriptAttributes ( opts ) ,
107+ beforeLoad : applyAttributesToScript ( buildClerkJsScriptAttributes ( opts ) ) ,
108108 } ) . catch ( error => {
109109 throw rejectWith ( error ) ;
110110 } ) ;
@@ -113,8 +113,6 @@ export const loadClerkJsScript = async (opts?: LoadClerkJsScriptOptions): Promis
113113} ;
114114
115115export const loadClerkUiScript = async ( opts ?: LoadClerkUiScriptOptions ) : Promise < HTMLScriptElement | null > => {
116- console . log ( 'here?' ) ;
117-
118116 const timeout = opts ?. scriptLoadTimeout ?? 15000 ;
119117 const rejectWith = ( error ?: Error ) =>
120118 new ClerkRuntimeError ( 'Failed to load Clerk UI' + ( error ?. message ? `, ${ error . message } ` : '' ) , {
@@ -142,8 +140,8 @@ export const loadClerkUiScript = async (opts?: LoadClerkUiScriptOptions): Promis
142140 async : true ,
143141 crossOrigin : 'anonymous' ,
144142 nonce : opts . nonce ,
143+ beforeLoad : applyAttributesToScript ( buildClerkUiScriptAttributes ( opts ) ) ,
145144 } ) . catch ( error => {
146- console . log ( 'nikos 2' , error ) ;
147145 throw rejectWith ( error ) ;
148146 } ) ;
149147
@@ -167,13 +165,11 @@ export const clerkUiScriptUrl = (opts: LoadClerkUiScriptOptions) => {
167165 const { clerkUiUrl, proxyUrl, domain, publishableKey } = opts ;
168166
169167 if ( clerkUiUrl ) {
170- console . log ( 'got clerk ui url' , clerkUiUrl ) ;
171-
172168 return clerkUiUrl ;
173169 }
174170
175171 const scriptHost = buildScriptHost ( { publishableKey, proxyUrl, domain } ) ;
176- // TODO @nikos add version selector
172+ // TODO: add version selector for clerk/ui similar to clerk-js
177173 return `https://${ scriptHost } /npm/@clerk/ui@latest/dist/ui.browser.js` ;
178174} ;
179175
@@ -199,8 +195,12 @@ export const buildClerkJsScriptAttributes = (options: LoadClerkJsScriptOptions)
199195 return obj ;
200196} ;
201197
202- const applyClerkJsScriptAttributes = ( options : LoadClerkJsScriptOptions ) => ( script : HTMLScriptElement ) => {
203- const attributes = buildClerkJsScriptAttributes ( options ) ;
198+ export const buildClerkUiScriptAttributes = ( options : LoadClerkUiScriptOptions ) => {
199+ // TODO @nikos do we need this?
200+ return buildClerkJsScriptAttributes ( options ) ;
201+ } ;
202+
203+ const applyAttributesToScript = ( attributes : Record < string , string > ) => ( script : HTMLScriptElement ) => {
204204 for ( const attribute in attributes ) {
205205 script . setAttribute ( attribute , attributes [ attribute ] ) ;
206206 }
0 commit comments