11import  hubspot  from  "../../hubspot.app.mjs" ; 
22import  { 
33  SEARCHABLE_OBJECT_TYPES , 
4-   SEARCHABLE_OBJECT_PROPERTIES , 
54  DEFAULT_CONTACT_PROPERTIES , 
65  DEFAULT_COMPANY_PROPERTIES , 
76  DEFAULT_DEAL_PROPERTIES , 
87  DEFAULT_TICKET_PROPERTIES , 
98  DEFAULT_PRODUCT_PROPERTIES , 
109  DEFAULT_LINE_ITEM_PROPERTIES , 
10+   DEFAULT_LEAD_PROPERTIES , 
1111}  from  "../../common/constants.mjs" ; 
1212import  common  from  "../common/common-create.mjs" ; 
1313
1414export  default  { 
1515  key : "hubspot-search-crm" , 
1616  name : "Search CRM" , 
17-   description : "Search companies, contacts, deals, feedback submissions, products, tickets, line-items, or quotes . [See the documentation](https://developers.hubspot.com/docs/api/crm/search)" , 
18-   version : "0.0.7 " , 
17+   description : "Search companies, contacts, deals, feedback submissions, products, tickets, line-items, quotes, leads,  or custom objects . [See the documentation](https://developers.hubspot.com/docs/api/crm/search)" , 
18+   version : "0.0.8 " , 
1919  type : "action" , 
2020  props : { 
2121    hubspot, 
2222    objectType : { 
2323      type : "string" , 
2424      label : "Object Type" , 
2525      description : "Type of CRM object to search for" , 
26-       options : SEARCHABLE_OBJECT_TYPES , 
26+       options : [ 
27+         ...SEARCHABLE_OBJECT_TYPES , 
28+         { 
29+           label : "Custom Object" , 
30+           value : "custom_object" , 
31+         } , 
32+       ] , 
2733      reloadProps : true , 
2834    } , 
2935    createIfNotFound : { 
@@ -37,11 +43,28 @@ export default {
3743  } , 
3844  async  additionalProps ( )  { 
3945    const  props  =  { } ; 
46+     if  ( this . objectType  ===  "custom_object" )  { 
47+       props . customObjectType  =  { 
48+         type : "string" , 
49+         label : "Custom Object Type" , 
50+         options : await  this . getCustomObjectTypes ( ) , 
51+         reloadProps : true , 
52+       } ; 
53+     } 
54+     if  ( ! this . objectType  ||  ( this . objectType  ===  "custom_object"  &&  ! this . customObjectType ) )  { 
55+       return  props ; 
56+     } 
57+ 
58+     const  objectType  =  this . customObjectType  ??  this . objectType ; 
59+     const  schema  =  await  this . hubspot . getSchema ( { 
60+       objectType, 
61+     } ) ; 
62+ 
4063    props . searchProperty  =  { 
4164      type : "string" , 
4265      label : "Search Property" , 
4366      description : "The field to search" , 
44-       options : this . getSearchProperties ( ) , 
67+       options : schema . searchableProperties , 
4568    } ; 
4669    props . searchValue  =  { 
4770      type : "string" , 
@@ -66,7 +89,7 @@ export default {
6689          return  [ ] ; 
6790        } 
6891        const  {  results : properties  }  =  await  this . hubspot . getProperties ( { 
69-           objectType : this . objectType , 
92+           objectType : this . customObjectType   ??   this . objectType , 
7093        } ) ; 
7194        const  defaultProperties  =  this . getDefaultProperties ( ) ; 
7295        return  properties . filter ( ( {  name } )  =>  ! defaultProperties . includes ( name ) ) 
@@ -77,12 +100,9 @@ export default {
77100      } , 
78101    } ; 
79102    let  creationProps  =  { } ; 
80-     if  ( this . createIfNotFound  &&  this . objectType )  { 
81-       const  schema  =  await  this . hubspot . getSchema ( { 
82-         objectType : this . objectType , 
83-       } ) ; 
103+     if  ( this . createIfNotFound  &&  objectType )  { 
84104      const  {  results : properties  }  =  await  this . hubspot . getProperties ( { 
85-         objectType :  this . objectType , 
105+         objectType, 
86106      } ) ; 
87107      creationProps  =  properties 
88108        . filter ( this . isRelevantProperty ) 
@@ -101,9 +121,6 @@ export default {
101121  } , 
102122  methods : { 
103123    ...common . methods , 
104-     getSearchProperties ( )  { 
105-       return  SEARCHABLE_OBJECT_PROPERTIES [ this . objectType ] ; 
106-     } , 
107124    getDefaultProperties ( )  { 
108125      if  ( this . objectType  ===  "contact" )  { 
109126        return  DEFAULT_CONTACT_PROPERTIES ; 
@@ -117,15 +134,22 @@ export default {
117134        return  DEFAULT_PRODUCT_PROPERTIES ; 
118135      }  else  if  ( this . objectType  ===  "line_item" )  { 
119136        return  DEFAULT_LINE_ITEM_PROPERTIES ; 
137+       }  else  if  ( this . objectType  ===  "lead" )  { 
138+         return  DEFAULT_LEAD_PROPERTIES ; 
120139      }  else  { 
121140        return  [ ] ; 
122141      } 
123142    } , 
143+     async  getCustomObjectTypes ( )  { 
144+       const  {  results }  =  await  this . hubspot . listSchemas ( ) ; 
145+       return  results ?. map ( ( {  name } )  =>  name  )  ||  [ ] ; 
146+     } , 
124147  } , 
125148  async  run ( {  $ } )  { 
126149    const  { 
127150      hubspot, 
128151      objectType, 
152+       customObjectType, 
129153      additionalProperties =  [ ] , 
130154      searchProperty, 
131155      searchValue, 
@@ -150,20 +174,20 @@ export default {
150174      ] , 
151175    } ; 
152176    const  {  results }  =  await  hubspot . searchCRM ( { 
153-       object : objectType , 
177+       object : customObjectType   ??   objectType , 
154178      data, 
155179      $, 
156180    } ) ; 
157181
158182    if  ( ! results ?. length  &&  createIfNotFound )  { 
159183      const  response  =  await  hubspot . createObject ( { 
160184        $, 
161-         objectType, 
185+         objectType :  customObjectType   ??   objectType , 
162186        data : { 
163187          properties, 
164188        } , 
165189      } ) ; 
166-       const  objectName  =  hubspot . getObjectTypeName ( objectType ) ; 
190+       const  objectName  =  hubspot . getObjectTypeName ( customObjectType   ??   objectType ) ; 
167191      $ . export ( "$summary" ,  `Successfully created ${ objectName }  ` ) ; 
168192      return  response ; 
169193    } 
0 commit comments