@@ -6,12 +6,14 @@ import {
66import common from "../common/common.mjs" ;
77import sampleEmit from "./test-event.mjs" ;
88
9+ const MAX_INITIAL_EVENTS = 25 ;
10+
911export default {
1012 ...common ,
1113 key : "hubspot-new-deal-in-stage" ,
1214 name : "New Deal In Stage" ,
1315 description : "Emit new event for each new deal in a stage." ,
14- version : "0.0.41 " ,
16+ version : "0.1.0 " ,
1517 dedupe : "unique" ,
1618 type : "source" ,
1719 props : {
@@ -59,16 +61,26 @@ export default {
5961 getParams ( ) {
6062 return null ;
6163 } ,
62- getStageParams ( stage ) {
63- const filter = {
64- propertyName : "dealstage" ,
65- operator : "EQ" ,
66- value : stage ,
67- } ;
64+ getAllStagesParams ( after ) {
65+ const filters = [
66+ {
67+ propertyName : "dealstage" ,
68+ operator : "IN" ,
69+ values : this . stages ,
70+ } ,
71+ ] ;
72+
73+ // Add time filter for subsequent runs to only get recently modified deals
74+ if ( after ) {
75+ filters . push ( {
76+ propertyName : "hs_lastmodifieddate" ,
77+ operator : "GT" ,
78+ value : after ,
79+ } ) ;
80+ }
81+
6882 const filterGroup = {
69- filters : [
70- filter ,
71- ] ,
83+ filters,
7284 } ;
7385 return {
7486 data : {
@@ -89,6 +101,7 @@ export default {
89101 } ,
90102 async processDeals ( params , after ) {
91103 let maxTs = after || 0 ;
104+ let initialEventsEmitted = 0 ;
92105
93106 do {
94107 const results = await this . hubspot . searchCRM ( params ) ;
@@ -111,20 +124,21 @@ export default {
111124 maxTs = ts ;
112125 this . _setAfter ( ts ) ;
113126 }
127+ if ( ! after && ++ initialEventsEmitted >= MAX_INITIAL_EVENTS ) {
128+ return ;
129+ }
114130 }
115131 }
116132
117133 // first run, get only first page
118134 if ( ! after ) {
119- return ;
135+ break ;
120136 }
121137 } while ( params . after ) ;
122138 } ,
123139 async processResults ( after ) {
124- for ( const stage of this . stages ) {
125- const params = this . getStageParams ( stage ) ;
126- await this . processDeals ( params , after ) ;
127- }
140+ const params = this . getAllStagesParams ( after ) ;
141+ await this . processDeals ( params , after ) ;
128142 } ,
129143 getOwner ( ownerId ) {
130144 return this . hubspot . makeRequest ( {
0 commit comments