Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/hubspot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hubspot",
"version": "0.11.0",
"version": "0.12.0",
"description": "Pipedream Hubspot Components",
"main": "hubspot.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
},
},
};
Loading