@@ -23,7 +23,7 @@ const redirectUrlRegex =
23
23
24
24
const redirectZodSchema = z . object ( {
25
25
url : z . string ( ) . regex ( redirectUrlRegex ) ,
26
- target : z . enum ( [ '_self' , '_blank' , '_parent' , '_top' , '_unfencedTop' ] ) . default ( '_blank' ) ,
26
+ target : z . enum ( [ '_self' , '_blank' , '_parent' , '_top' , '_unfencedTop' ] ) ,
27
27
} ) ;
28
28
29
29
const actionZodSchema = z
@@ -33,18 +33,32 @@ const actionZodSchema = z
33
33
} )
34
34
. optional ( ) ;
35
35
36
- export const inAppControlZodSchema = z . object ( {
36
+ // First, define the common properties that both schema variants will share
37
+ const commonInAppProperties = {
37
38
skip : skipZodSchema ,
38
39
disableOutputSanitization : z . boolean ( ) . optional ( ) ,
39
- subject : z . string ( ) . optional ( ) ,
40
- body : z . string ( ) ,
41
40
avatar : z . string ( ) . regex ( redirectUrlRegex ) . optional ( ) ,
42
41
primaryAction : actionZodSchema ,
43
42
secondaryAction : actionZodSchema ,
44
43
data : z . object ( { } ) . catchall ( z . unknown ( ) ) . optional ( ) ,
45
44
redirect : redirectZodSchema . optional ( ) ,
45
+ } ;
46
+
47
+ const subjectRequiredSchema = z . object ( {
48
+ subject : z . string ( ) ,
49
+ body : z . string ( ) . optional ( ) ,
50
+ ...commonInAppProperties ,
46
51
} ) ;
47
52
53
+ const bodyRequiredSchema = z . object ( {
54
+ subject : z . string ( ) . optional ( ) ,
55
+ body : z . string ( ) ,
56
+ ...commonInAppProperties ,
57
+ } ) ;
58
+
59
+ // Write it this way because of how translation from zod to json schema works
60
+ export const inAppControlZodSchema = z . union ( [ subjectRequiredSchema , bodyRequiredSchema ] ) ;
61
+
48
62
export type InAppRedirectType = z . infer < typeof redirectZodSchema > ;
49
63
export type InAppActionType = z . infer < typeof actionZodSchema > ;
50
64
export type InAppControlType = z . infer < typeof inAppControlZodSchema > ;
0 commit comments