11import type { ClerkOptions } from '@clerk/types' ;
22import type { AstroIntegration } from 'astro' ;
3+ import { envField } from 'astro/config' ;
34
45import { name as packageName , version as packageVersion } from '../../package.json' ;
56import type { AstroClerkIntegrationParams } from '../types' ;
@@ -13,11 +14,12 @@ type HotloadAstroClerkIntegrationParams = AstroClerkIntegrationParams & {
1314 clerkJSUrl ?: string ;
1415 clerkJSVariant ?: 'headless' | '' ;
1516 clerkJSVersion ?: string ;
17+ enableEnvSchema ?: boolean ;
1618} ;
1719
1820function createIntegration < Params extends HotloadAstroClerkIntegrationParams > ( ) {
1921 return ( params ?: Params ) : AstroIntegration => {
20- const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl } = params || { } ;
22+ const { proxyUrl, isSatellite, domain, signInUrl, signUpUrl, enableEnvSchema = true } = params || { } ;
2123
2224 // These are not provided when the "bundled" integration is used
2325 const clerkJSUrl = ( params as any ) ?. clerkJSUrl as string | undefined ;
@@ -79,6 +81,11 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
7981 target : 'es2022' ,
8082 } ,
8183 } ,
84+ env : {
85+ schema : {
86+ ...( enableEnvSchema ? createClerkEnvSchema ( ) : { } ) ,
87+ } ,
88+ } ,
8289 } ) ;
8390
8491 /**
@@ -158,4 +165,27 @@ function createIntegration<Params extends HotloadAstroClerkIntegrationParams>()
158165 } ;
159166}
160167
168+ function createClerkEnvSchema ( ) {
169+ return {
170+ PUBLIC_CLERK_PUBLISHABLE_KEY : envField . string ( { context : 'client' , access : 'public' } ) ,
171+ PUBLIC_CLERK_SIGN_IN_URL : envField . string ( { context : 'client' , access : 'public' , optional : true } ) ,
172+ PUBLIC_CLERK_SIGN_UP_URL : envField . string ( { context : 'client' , access : 'public' , optional : true } ) ,
173+ PUBLIC_CLERK_IS_SATELLITE : envField . boolean ( { context : 'client' , access : 'public' , optional : true } ) ,
174+ PUBLIC_CLERK_PROXY_URL : envField . string ( { context : 'client' , access : 'public' , optional : true , url : true } ) ,
175+ PUBLIC_CLERK_DOMAIN : envField . string ( { context : 'client' , access : 'public' , optional : true , url : true } ) ,
176+ PUBLIC_CLERK_JS_URL : envField . string ( { context : 'client' , access : 'public' , optional : true , url : true } ) ,
177+ PUBLIC_CLERK_JS_VARIANT : envField . enum ( {
178+ context : 'client' ,
179+ access : 'public' ,
180+ optional : true ,
181+ values : [ 'headless' ] ,
182+ } ) ,
183+ PUBLIC_CLERK_JS_VERSION : envField . string ( { context : 'client' , access : 'public' , optional : true } ) ,
184+ PUBLIC_CLERK_TELEMETRY_DISABLED : envField . boolean ( { context : 'client' , access : 'public' , optional : true } ) ,
185+ PUBLIC_CLERK_TELEMETRY_DEBUG : envField . boolean ( { context : 'client' , access : 'public' , optional : true } ) ,
186+ CLERK_SECRET_KEY : envField . string ( { context : 'server' , access : 'secret' } ) ,
187+ CLERK_JWT_KEY : envField . string ( { context : 'server' , access : 'secret' , optional : true } ) ,
188+ } ;
189+ }
190+
161191export { createIntegration } ;
0 commit comments