11import { client } from '@/platforms/outreach/client' ;
22import { action } from '@/sdk' ;
3+ import { omit } from 'radash' ;
34import { z } from 'zod' ;
45
6+ const customFieldsSchema = z
7+ . record (
8+ z
9+ . string ( )
10+ . regex ( / ^ c u s t o m [ 0 - 9 ] + $ / , 'Custom fields must be of the form custom[0-9]+' )
11+ . transform ( ( key ) => key as `custom${number } `) ,
12+ z . string ( ) . nullable ( ) ,
13+ )
14+ . optional ( ) ;
15+
16+ const attributesSchema = z . object ( {
17+ firstName : z . string ( ) . nullish ( ) ,
18+ lastName : z . string ( ) . nullish ( ) ,
19+ occupation : z . string ( ) . nullish ( ) ,
20+ addressCity : z . string ( ) . nullish ( ) ,
21+ addressCountry : z . string ( ) . nullish ( ) ,
22+ addressState : z . string ( ) . nullish ( ) ,
23+ addressStreet : z . string ( ) . nullish ( ) ,
24+ addressStreet2 : z . string ( ) . nullish ( ) ,
25+ addressZip : z . string ( ) . nullish ( ) ,
26+ emails : z . array ( z . string ( ) ) . optional ( ) ,
27+ } ) ;
28+
529export default action (
630 'create-prospect' ,
731 {
@@ -10,28 +34,17 @@ export default action(
1034 mutation : true ,
1135 schema : z . object ( {
1236 attributes : z
13- . object ( {
14- firstName : z . string ( ) . nullish ( ) ,
15- lastName : z . string ( ) . nullish ( ) ,
16- occupation : z . string ( ) . nullish ( ) ,
17- addressCity : z . string ( ) . nullish ( ) ,
18- addressCountry : z . string ( ) . nullish ( ) ,
19- addressState : z . string ( ) . nullish ( ) ,
20- addressStreet : z . string ( ) . nullish ( ) ,
21- addressStreet2 : z . string ( ) . nullish ( ) ,
22- addressZip : z . string ( ) . nullish ( ) ,
23- emails : z . array ( z . string ( ) ) . optional ( ) ,
24- } )
25- . catchall (
26- z
27- . string ( )
28- . regex (
29- / ^ c u s t o m [ 0 - 9 ] + $ / ,
30- 'Custom fields must be of the form custom[0-9]+' ,
31- )
32- . transform ( ( key ) => key as `custom${number } `)
33- . nullable ( ) ,
34- ) ,
37+ . preprocess ( ( input ) => {
38+ const attributes = attributesSchema . parse ( input ) ;
39+ const customFields = customFieldsSchema . parse (
40+ omit ( input as any , Object . keys ( attributes ) ) ,
41+ ) ;
42+ return { customFields, ...attributes } ;
43+ } , attributesSchema . extend ( { customFields : customFieldsSchema } ) )
44+ . transform ( ( attr ) => ( {
45+ ...omit ( attr , [ 'customFields' ] ) ,
46+ ...attr . customFields ,
47+ } ) ) ,
3548 relationships : z . object ( {
3649 ownerId : z . number ( ) . optional ( ) ,
3750 accountId : z . number ( ) . optional ( ) ,
0 commit comments