File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,13 +22,30 @@ export const clickWebhookEventSchema = z.object({
2222 link : linkEventSchema ,
2323} ) ;
2424
25+ const coerceJsonString = ( val : unknown ) => {
26+ if ( typeof val === "string" ) {
27+ try {
28+ return JSON . parse ( val ) ;
29+ } catch {
30+ return val ;
31+ }
32+ }
33+
34+ return val ;
35+ } ;
36+
37+ const metadataSchema = z . preprocess (
38+ coerceJsonString ,
39+ z . record ( z . string ( ) , z . any ( ) ) . nullish ( ) . default ( null ) ,
40+ ) ;
41+
2542export const leadWebhookEventSchema = z . object ( {
2643 eventName : z . string ( ) ,
2744 customer : CustomerSchema ,
2845 click : clickEventSchema ,
2946 link : linkEventSchema ,
3047 partner : WebhookPartnerSchema . nullish ( ) ,
31- metadata : z . record ( z . string ( ) , z . any ( ) ) . nullable ( ) . default ( null ) ,
48+ metadata : metadataSchema ,
3249} ) ;
3350
3451export const saleWebhookEventSchema = z . object ( {
@@ -38,7 +55,7 @@ export const saleWebhookEventSchema = z.object({
3855 link : linkEventSchema ,
3956 sale : webhookSaleSchema ,
4057 partner : WebhookPartnerSchema . nullish ( ) ,
41- metadata : z . record ( z . string ( ) , z . any ( ) ) . nullable ( ) . default ( null ) ,
58+ metadata : metadataSchema ,
4259} ) ;
4360
4461// Schema of the payload sent to the webhook endpoint by Dub
You can’t perform that action at this time.
0 commit comments