@@ -4,21 +4,21 @@ import {
44 DEFAULT_CONTACT_PROPERTIES ,
55 DEFAULT_DEAL_PROPERTIES ,
66 DEFAULT_LEAD_PROPERTIES ,
7- DEFAULT_LIMIT ,
87 DEFAULT_LINE_ITEM_PROPERTIES ,
98 DEFAULT_PRODUCT_PROPERTIES ,
109 DEFAULT_TICKET_PROPERTIES ,
1110 SEARCHABLE_OBJECT_TYPES ,
1211} from "../../common/constants.mjs" ;
1312import hubspot from "../../hubspot.app.mjs" ;
1413import common from "../common/common-create.mjs" ;
14+ const DEFAULT_LIMIT = 200 ;
1515
1616export default {
1717 key : "hubspot-search-crm" ,
1818 name : "Search CRM" ,
1919 description :
2020 "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)" ,
21- version : "1.0.12 " ,
21+ version : "1.1.0 " ,
2222 type : "action" ,
2323 props : {
2424 hubspot,
@@ -52,6 +52,13 @@ export default {
5252 optional : true ,
5353 reloadProps : true ,
5454 } ,
55+ offset : {
56+ type : "integer" ,
57+ label : "Offset" ,
58+ description : "The offset to start from. Used for pagination." ,
59+ default : 0 ,
60+ optional : true ,
61+ } ,
5562 } ,
5663 async additionalProps ( ) {
5764 const props = { } ;
@@ -224,23 +231,6 @@ export default {
224231 } ) ) || [ ]
225232 ) ;
226233 } ,
227- async paginate ( params ) {
228- let results ;
229- const items = [ ] ;
230- while ( ! results || params . after ) {
231- results = await this . hubspot . searchCRM ( params ) ;
232- if ( results . paging ) {
233- params . after = results . paging . next . after ;
234- } else {
235- delete params . after ;
236- }
237- results = results . results ;
238- for ( const result of results ) {
239- items . push ( result ) ;
240- }
241- }
242- return items ;
243- } ,
244234 } ,
245235 async run ( { $ } ) {
246236 const {
@@ -251,6 +241,7 @@ export default {
251241 searchProperty,
252242 searchValue,
253243 exactMatch,
244+ offset,
254245 /* eslint-disable no-unused-vars */
255246 info,
256247 createIfNotFound,
@@ -282,8 +273,18 @@ export default {
282273 properties : [
283274 ...defaultProperties ,
284275 ...additionalProperties ,
276+ searchProperty ,
285277 ] ,
278+ sorts : [
279+ {
280+ propertyName : "createdate" ,
281+ direction : "DESCENDING" ,
282+ } ,
283+ ] ,
284+ limit : DEFAULT_LIMIT ,
285+ after : offset ,
286286 } ;
287+
287288 if ( exactMatch ) {
288289 data . filters = [
289290 {
@@ -292,17 +293,17 @@ export default {
292293 value : searchValue ,
293294 } ,
294295 ] ;
295- } else {
296- data . limit = DEFAULT_LIMIT ;
297296 }
298297
299- let results = await this . paginate ( {
298+ let {
299+ results, paging,
300+ } = await this . hubspot . searchCRM ( {
300301 object : actualObjectType ,
301302 data,
302303 } ) ;
303304
304305 if ( ! exactMatch ) {
305- results = results . filter (
306+ results = results ? .filter (
306307 ( result ) =>
307308 result . properties [ searchProperty ] &&
308309 result . properties [ searchProperty ]
@@ -328,6 +329,9 @@ export default {
328329 "$summary" ,
329330 `Successfully retrieved ${ results ?. length } object(s).` ,
330331 ) ;
331- return results ;
332+ return {
333+ results,
334+ paging,
335+ } ;
332336 } ,
333337} ;
0 commit comments