8
8
DEFAULT_PRODUCT_PROPERTIES ,
9
9
DEFAULT_LINE_ITEM_PROPERTIES ,
10
10
DEFAULT_LEAD_PROPERTIES ,
11
+ DEFAULT_LIMIT ,
11
12
} from "../../common/constants.mjs" ;
12
13
import common from "../common/common-create.mjs" ;
13
14
import { ConfigurationError } from "@pipedream/platform" ;
@@ -16,7 +17,7 @@ export default {
16
17
key : "hubspot-search-crm" ,
17
18
name : "Search CRM" ,
18
19
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 " ,
20
21
type : "action" ,
21
22
props : {
22
23
hubspot,
@@ -33,6 +34,13 @@ export default {
33
34
] ,
34
35
reloadProps : true ,
35
36
} ,
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
+ } ,
36
44
createIfNotFound : {
37
45
type : "boolean" ,
38
46
label : "Create if not found?" ,
@@ -97,7 +105,7 @@ export default {
97
105
props . searchValue = {
98
106
type : "string" ,
99
107
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" ,
101
109
} ;
102
110
const defaultProperties = this . getDefaultProperties ( ) ;
103
111
if ( defaultProperties ?. length ) {
@@ -201,6 +209,23 @@ export default {
201
209
label : labels . plural ,
202
210
} ) ) || [ ] ;
203
211
} ,
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
+ } ,
204
229
} ,
205
230
async run ( { $ } ) {
206
231
const {
@@ -210,6 +235,7 @@ export default {
210
235
additionalProperties = [ ] ,
211
236
searchProperty,
212
237
searchValue,
238
+ exactMatch,
213
239
/* eslint-disable no-unused-vars */
214
240
info,
215
241
createIfNotFound,
@@ -242,20 +268,30 @@ export default {
242
268
...defaultProperties ,
243
269
...additionalProperties ,
244
270
] ,
245
- filters : [
271
+ } ;
272
+ if ( exactMatch ) {
273
+ data . filters = [
246
274
{
247
275
propertyName : searchProperty ,
248
276
operator : "EQ" ,
249
277
value : searchValue ,
250
278
} ,
251
- ] ,
252
- } ;
253
- const { results } = await hubspot . searchCRM ( {
279
+ ] ;
280
+ } else {
281
+ data . limit = DEFAULT_LIMIT ;
282
+ }
283
+
284
+ let results = await this . paginate ( {
254
285
object : actualObjectType ,
255
286
data,
256
- $,
257
287
} ) ;
258
288
289
+ if ( ! exactMatch ) {
290
+ results = results . filter ( ( result ) =>
291
+ result . properties [ searchProperty ]
292
+ && result . properties [ searchProperty ] . toLowerCase ( ) . includes ( searchValue . toLowerCase ( ) ) ) ;
293
+ }
294
+
259
295
if ( ! results ?. length && createIfNotFound ) {
260
296
const response = await hubspot . createObject ( {
261
297
$,
0 commit comments