diff --git a/components/hubspot/package.json b/components/hubspot/package.json index 237df088fc68f..838c13653f25b 100644 --- a/components/hubspot/package.json +++ b/components/hubspot/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/hubspot", - "version": "0.11.0", + "version": "0.12.0", "description": "Pipedream Hubspot Components", "main": "hubspot.app.mjs", "keywords": [ diff --git a/components/hubspot/sources/new-custom-object-property-change/new-custom-object-property-change.mjs b/components/hubspot/sources/new-custom-object-property-change/new-custom-object-property-change.mjs new file mode 100644 index 0000000000000..c0ba63fd6ee0a --- /dev/null +++ b/components/hubspot/sources/new-custom-object-property-change/new-custom-object-property-change.mjs @@ -0,0 +1,122 @@ +import common from "../common/common.mjs"; +import { DEFAULT_LIMIT } from "../../common/constants.mjs"; + +export default { + ...common, + key: "hubspot-new-custom-object-property-change", + name: "New Custom Object Property Change", + description: "Emit new event when a specified property is provided or updated on a custom object.", + version: "0.0.1", + dedupe: "unique", + type: "source", + props: { + ...common.props, + objectSchema: { + propDefinition: [ + common.props.hubspot, + "objectSchema", + ], + }, + property: { + type: "string", + label: "Property", + description: "The custom object property to watch for changes", + async options() { + const properties = await this.getWriteOnlyProperties(this.objectSchema); + return properties.map((property) => property.name); + }, + }, + }, + methods: { + ...common.methods, + getTs(object) { + const history = object.propertiesWithHistory[this.property]; + if (!history || !(history.length > 0)) { + return; + } + return Date.parse(history[0].timestamp); + }, + generateMeta(object) { + const { + id, + properties, + } = object; + const ts = this.getTs(object); + return { + id: `${id}${ts}`, + summary: properties[this.property], + ts, + }; + }, + isRelevant(object, updatedAfter) { + return !updatedAfter || this.getTs(object) > updatedAfter; + }, + getParams(after) { + return { + object: this.objectSchema, + data: { + limit: DEFAULT_LIMIT, + properties: [ + this.property, + ], + sorts: [ + { + propertyName: "hs_lastmodifieddate", + direction: "DESCENDING", + }, + ], + filterGroups: [ + { + filters: [ + { + propertyName: this.property, + operator: "HAS_PROPERTY", + }, + { + propertyName: "hs_lastmodifieddate", + operator: "GTE", + value: after, + }, + ], + }, + ], + }, + }; + }, + batchGetCustomObjects(inputs) { + return this.hubspot.batchGetObjects({ + objectType: this.objectSchema, + data: { + properties: [ + this.property, + ], + propertiesWithHistory: [ + this.property, + ], + inputs, + }, + }); + }, + async processResults(after, params) { + const properties = await this.getWriteOnlyProperties(this.objectSchema); + const propertyNames = properties.map((property) => property.name); + + if (!propertyNames.includes(this.property)) { + throw new Error(`Property "${this.property}" not supported for custom object ${this.objectSchema}.`); + } + + const updatedObjects = await this.getPaginatedItems(this.hubspot.searchCRM, params); + + if (!updatedObjects.length) { + return; + } + + const results = await this.processChunks({ + batchRequestFn: this.batchGetCustomObjects, + chunks: this.getChunks(updatedObjects), + }); + + this.processEvents(results, after); + }, + }, +};