@@ -11,7 +11,7 @@ const nameValidation = z
1111const domainsValidation = z . string ( ) . refine (
1212 ( str ) =>
1313 validStrList ( str , ( domain ) => {
14- return domain . split ( " :") [ 0 ] === "localhost" || RE_DOMAIN . test ( domain ) ;
14+ return domain . startsWith ( "localhost :") || RE_DOMAIN . test ( domain ) ;
1515 } ) ,
1616 {
1717 message : "Some of the domains are invalid" ,
@@ -95,26 +95,55 @@ export const apiKeyCreateValidationSchema = z.object({
9595 services : servicesValidation ,
9696} ) ;
9797
98- export const apiKeyValidationSchema = z . object ( {
98+ function isValidRedirectURI ( uri : string ) {
99+ // whitespace is not allowed
100+ if ( / \s / g. test ( uri ) ) {
101+ return false ;
102+ }
103+
104+ // foo://... is allowed
105+ if ( uri . includes ( "://" ) ) {
106+ return true ;
107+ }
108+
109+ // localhost:... is allowed
110+ if ( uri . startsWith ( "localhost:" ) ) {
111+ return true ;
112+ }
113+
114+ // valid url is allowed
115+ try {
116+ new URL ( uri ) ;
117+ return true ;
118+ } catch {
119+ // invalid
120+ }
121+
122+ // everything else is invalid
123+ return false ;
124+ }
125+
126+ const redirectUriSchema = z
127+ . string ( )
128+ . refine ( ( str ) => validStrList ( str , isValidRedirectURI ) , {
129+ message :
130+ "Some of the redirect URIs are invalid. Make sure they are valid URIs and do not contain spaces." ,
131+ } )
132+ . refine ( ( str ) => str !== "*" , {
133+ message : "Wildcard redirect URIs are not allowed" ,
134+ } ) ;
135+
136+ // TODO: move this schema to project settings folder in separate PR
137+ export const projectSettingsPageFormSchema = z . object ( {
99138 name : nameValidation ,
100139 domains : domainsValidation ,
101140 services : servicesValidation ,
102141 bundleIds : z . string ( ) . refine ( ( str ) => validStrList ( str , RE_BUNDLE_ID ) , {
103142 message : "Some of the bundle ids are invalid" ,
104143 } ) ,
105- redirectUrls : z
106- . string ( )
107- . refine (
108- ( str ) =>
109- validStrList ( str , ( url ) => url . includes ( "://" ) && ! / \s / g. test ( url ) ) ,
110- {
111- message :
112- "Some of the redirect URIs are invalid. Make sure they are valid URIs and do not contain spaces." ,
113- } ,
114- )
115- . refine ( ( str ) => str !== "*" , {
116- message : "Wildcard redirect URIs are not allowed" ,
117- } ) ,
144+ // no strict validation for redirectUrls, because project general page does not render redirectUrls form field
145+ // so if the user has already saved an invalid `redirectUrls` on in-app wallet project settings page ( which is fixed now ) - it won't prevent them from updating the general project settings
146+ redirectUrls : z . string ( ) ,
118147} ) ;
119148
120149export const apiKeyEmbeddedWalletsValidationSchema = z . object ( {
@@ -127,7 +156,7 @@ export const apiKeyEmbeddedWalletsValidationSchema = z.object({
127156 applicationImageUrl : applicationImageUrlValidation ,
128157 } ) ,
129158 ] ) ,
130- redirectUrls : z . union ( [ z . undefined ( ) , z . string ( ) ] ) ,
159+ redirectUrls : redirectUriSchema ,
131160} ) ;
132161
133162export const apiKeyPayConfigValidationSchema = z . object ( {
@@ -138,7 +167,9 @@ export type ApiKeyCreateValidationSchema = z.infer<
138167 typeof apiKeyCreateValidationSchema
139168> ;
140169
141- export type ApiKeyValidationSchema = z . infer < typeof apiKeyValidationSchema > ;
170+ export type ProjectSettingsPageFormSchema = z . infer <
171+ typeof projectSettingsPageFormSchema
172+ > ;
142173
143174export type ApiKeyEmbeddedWalletsValidationSchema = z . infer <
144175 typeof apiKeyEmbeddedWalletsValidationSchema
0 commit comments