88 DEFAULT_PRODUCT_PROPERTIES ,
99 DEFAULT_LINE_ITEM_PROPERTIES ,
1010 DEFAULT_LEAD_PROPERTIES ,
11+ DEFAULT_LIMIT ,
1112} from "../../common/constants.mjs" ;
1213import common from "../common/common-create.mjs" ;
1314import { ConfigurationError } from "@pipedream/platform" ;
@@ -16,7 +17,7 @@ export default {
1617 key : "hubspot-search-crm" ,
1718 name : "Search CRM" ,
1819 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)" ,
19- version : "1.0.3 " ,
20+ version : "1.0.4 " ,
2021 type : "action" ,
2122 props : {
2223 hubspot,
@@ -33,6 +34,13 @@ export default {
3334 ] ,
3435 reloadProps : true ,
3536 } ,
37+ exactMatch : {
38+ type : "boolean" ,
39+ label : "Exact Match" ,
40+ description : "Set to `true` to search for an exact match of the search value. If `false`, partial matches will be returned. Default: `true`" ,
41+ default : true ,
42+ optional : true ,
43+ } ,
3644 createIfNotFound : {
3745 type : "boolean" ,
3846 label : "Create if not found?" ,
@@ -97,7 +105,7 @@ export default {
97105 props . searchValue = {
98106 type : "string" ,
99107 label : "Search Value" ,
100- description : "Search for objects where the specified search field/property contains an exact match of the search value" ,
108+ description : "Search for objects where the specified search field/property contains a match of the search value" ,
101109 } ;
102110 const defaultProperties = this . getDefaultProperties ( ) ;
103111 if ( defaultProperties ?. length ) {
@@ -201,6 +209,23 @@ export default {
201209 label : labels . plural ,
202210 } ) ) || [ ] ;
203211 } ,
212+ async paginate ( params ) {
213+ let results ;
214+ const items = [ ] ;
215+ while ( ! results || params . after ) {
216+ results = await this . hubspot . searchCRM ( params ) ;
217+ if ( results . paging ) {
218+ params . after = results . paging . next . after ;
219+ } else {
220+ delete params . after ;
221+ }
222+ results = results . results ;
223+ for ( const result of results ) {
224+ items . push ( result ) ;
225+ }
226+ }
227+ return items ;
228+ } ,
204229 } ,
205230 async run ( { $ } ) {
206231 const {
@@ -210,6 +235,7 @@ export default {
210235 additionalProperties = [ ] ,
211236 searchProperty,
212237 searchValue,
238+ exactMatch,
213239 /* eslint-disable no-unused-vars */
214240 info,
215241 createIfNotFound,
@@ -242,20 +268,30 @@ export default {
242268 ...defaultProperties ,
243269 ...additionalProperties ,
244270 ] ,
245- filters : [
271+ } ;
272+ if ( exactMatch ) {
273+ data . filters = [
246274 {
247275 propertyName : searchProperty ,
248276 operator : "EQ" ,
249277 value : searchValue ,
250278 } ,
251- ] ,
252- } ;
253- const { results } = await hubspot . searchCRM ( {
279+ ] ;
280+ } else {
281+ data . limit = DEFAULT_LIMIT ;
282+ }
283+
284+ let results = await this . paginate ( {
254285 object : actualObjectType ,
255286 data,
256- $,
257287 } ) ;
258288
289+ if ( ! exactMatch ) {
290+ results = results . filter ( ( result ) =>
291+ result . properties [ searchProperty ]
292+ && result . properties [ searchProperty ] . toLowerCase ( ) . includes ( searchValue . toLowerCase ( ) ) ) ;
293+ }
294+
259295 if ( ! results ?. length && createIfNotFound ) {
260296 const response = await hubspot . createObject ( {
261297 $,
0 commit comments