From c7cb480707e9a6ae42a05ba4ddb3275b49846972 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 13 Dec 2024 13:40:47 -0500 Subject: [PATCH 1/2] new-custom-object-property-change --- components/hubspot/package.json | 2 +- .../new-custom-object-property-change.mjs | 122 ++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 components/hubspot/sources/new-custom-object-property-change/new-custom-object-property-change.mjs 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..175a311002323 --- /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 company 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); + }, + }, +}; From 4588c904093a96500f07daac8f040baef682d71d Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 13 Dec 2024 13:49:43 -0500 Subject: [PATCH 2/2] fix prop description --- .../new-custom-object-property-change.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 175a311002323..c0ba63fd6ee0a 100644 --- 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 @@ -20,7 +20,7 @@ export default { property: { type: "string", label: "Property", - description: "The company property to watch for changes", + description: "The custom object property to watch for changes", async options() { const properties = await this.getWriteOnlyProperties(this.objectSchema); return properties.map((property) => property.name);