Skip to content

Commit 8e8ce01

Browse files
committed
update search-crm
1 parent 263d42e commit 8e8ce01

File tree

4 files changed

+58
-81
lines changed

4 files changed

+58
-81
lines changed

components/hubspot/actions/search-crm/search-crm.mjs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import hubspot from "../../hubspot.app.mjs";
22
import {
33
SEARCHABLE_OBJECT_TYPES,
4-
SEARCHABLE_OBJECT_PROPERTIES,
54
DEFAULT_CONTACT_PROPERTIES,
65
DEFAULT_COMPANY_PROPERTIES,
76
DEFAULT_DEAL_PROPERTIES,
87
DEFAULT_TICKET_PROPERTIES,
98
DEFAULT_PRODUCT_PROPERTIES,
109
DEFAULT_LINE_ITEM_PROPERTIES,
10+
DEFAULT_LEAD_PROPERTIES,
1111
} from "../../common/constants.mjs";
1212
import common from "../common/common-create.mjs";
1313

1414
export default {
1515
key: "hubspot-search-crm",
1616
name: "Search CRM",
17-
description: "Search companies, contacts, deals, feedback submissions, products, tickets, line-items, or quotes. [See the documentation](https://developers.hubspot.com/docs/api/crm/search)",
18-
version: "0.0.7",
17+
description: "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)",
18+
version: "0.0.8",
1919
type: "action",
2020
props: {
2121
hubspot,
2222
objectType: {
2323
type: "string",
2424
label: "Object Type",
2525
description: "Type of CRM object to search for",
26-
options: SEARCHABLE_OBJECT_TYPES,
26+
options: [
27+
...SEARCHABLE_OBJECT_TYPES,
28+
{
29+
label: "Custom Object",
30+
value: "custom_object",
31+
},
32+
],
2733
reloadProps: true,
2834
},
2935
createIfNotFound: {
@@ -37,11 +43,28 @@ export default {
3743
},
3844
async additionalProps() {
3945
const props = {};
46+
if (this.objectType === "custom_object") {
47+
props.customObjectType = {
48+
type: "string",
49+
label: "Custom Object Type",
50+
options: await this.getCustomObjectTypes(),
51+
reloadProps: true,
52+
};
53+
}
54+
if (!this.objectType || (this.objectType === "custom_object" && !this.customObjectType)) {
55+
return props;
56+
}
57+
58+
const objectType = this.customObjectType ?? this.objectType;
59+
const schema = await this.hubspot.getSchema({
60+
objectType,
61+
});
62+
4063
props.searchProperty = {
4164
type: "string",
4265
label: "Search Property",
4366
description: "The field to search",
44-
options: this.getSearchProperties(),
67+
options: schema.searchableProperties,
4568
};
4669
props.searchValue = {
4770
type: "string",
@@ -66,7 +89,7 @@ export default {
6689
return [];
6790
}
6891
const { results: properties } = await this.hubspot.getProperties({
69-
objectType: this.objectType,
92+
objectType: this.customObjectType ?? this.objectType,
7093
});
7194
const defaultProperties = this.getDefaultProperties();
7295
return properties.filter(({ name }) => !defaultProperties.includes(name))
@@ -77,12 +100,9 @@ export default {
77100
},
78101
};
79102
let creationProps = {};
80-
if (this.createIfNotFound && this.objectType) {
81-
const schema = await this.hubspot.getSchema({
82-
objectType: this.objectType,
83-
});
103+
if (this.createIfNotFound && objectType) {
84104
const { results: properties } = await this.hubspot.getProperties({
85-
objectType: this.objectType,
105+
objectType,
86106
});
87107
creationProps = properties
88108
.filter(this.isRelevantProperty)
@@ -101,9 +121,6 @@ export default {
101121
},
102122
methods: {
103123
...common.methods,
104-
getSearchProperties() {
105-
return SEARCHABLE_OBJECT_PROPERTIES[this.objectType];
106-
},
107124
getDefaultProperties() {
108125
if (this.objectType === "contact") {
109126
return DEFAULT_CONTACT_PROPERTIES;
@@ -117,15 +134,22 @@ export default {
117134
return DEFAULT_PRODUCT_PROPERTIES;
118135
} else if (this.objectType === "line_item") {
119136
return DEFAULT_LINE_ITEM_PROPERTIES;
137+
} else if (this.objectType === "lead") {
138+
return DEFAULT_LEAD_PROPERTIES;
120139
} else {
121140
return [];
122141
}
123142
},
143+
async getCustomObjectTypes() {
144+
const { results } = await this.hubspot.listSchemas();
145+
return results?.map(({ name }) => name ) || [];
146+
},
124147
},
125148
async run({ $ }) {
126149
const {
127150
hubspot,
128151
objectType,
152+
customObjectType,
129153
additionalProperties = [],
130154
searchProperty,
131155
searchValue,
@@ -150,20 +174,20 @@ export default {
150174
],
151175
};
152176
const { results } = await hubspot.searchCRM({
153-
object: objectType,
177+
object: customObjectType ?? objectType,
154178
data,
155179
$,
156180
});
157181

158182
if (!results?.length && createIfNotFound) {
159183
const response = await hubspot.createObject({
160184
$,
161-
objectType,
185+
objectType: customObjectType ?? objectType,
162186
data: {
163187
properties,
164188
},
165189
});
166-
const objectName = hubspot.getObjectTypeName(objectType);
190+
const objectName = hubspot.getObjectTypeName(customObjectType ?? objectType);
167191
$.export("$summary", `Successfully created ${objectName}`);
168192
return response;
169193
}

components/hubspot/common/constants.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
OBJECT_TYPE,
44
OBJECT_TYPES,
55
SEARCHABLE_OBJECT_TYPES,
6-
SEARCHABLE_OBJECT_PROPERTIES,
76
} from "./object-types.mjs";
87

98
const BASE_URL = "https://api.hubapi.com";
@@ -160,6 +159,15 @@ const DEFAULT_LINE_ITEM_PROPERTIES = [
160159
"hs_term_in_months",
161160
];
162161

162+
const DEFAULT_LEAD_PROPERTIES = [
163+
"hs_associated_contact_email",
164+
"hs_associated_contact_lastname",
165+
"hs_lead_name",
166+
"hs_associated_company_domain",
167+
"hs_associated_contact_firstname",
168+
"hs_associated_company_name",
169+
];
170+
163171
const ENGAGEMENT_TYPE_OPTIONS = [
164172
{
165173
label: "Note",
@@ -187,7 +195,6 @@ export {
187195
OBJECT_TYPE,
188196
OBJECT_TYPES,
189197
SEARCHABLE_OBJECT_TYPES,
190-
SEARCHABLE_OBJECT_PROPERTIES,
191198
HUBSPOT_OWNER,
192199
BASE_URL,
193200
API_PATH,
@@ -199,5 +206,6 @@ export {
199206
DEFAULT_TICKET_PROPERTIES,
200207
DEFAULT_PRODUCT_PROPERTIES,
201208
DEFAULT_LINE_ITEM_PROPERTIES,
209+
DEFAULT_LEAD_PROPERTIES,
202210
ENGAGEMENT_TYPE_OPTIONS,
203211
};

components/hubspot/common/object-types.mjs

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const OBJECT_TYPE = {
1717
NOTE: "note",
1818
EMAIL: "email",
1919
TASK: "task",
20+
LEAD: "lead",
2021
};
2122

2223
/**
@@ -77,6 +78,10 @@ const OBJECT_TYPES = [
7778
label: "Tasks",
7879
value: OBJECT_TYPE.TASK,
7980
},
81+
{
82+
label: "Leads",
83+
value: OBJECT_TYPE.LEAD,
84+
},
8085
];
8186

8287
const SEARCHABLE_OBJECT_TYPES_ARRAY = [
@@ -87,71 +92,12 @@ const SEARCHABLE_OBJECT_TYPES_ARRAY = [
8792
OBJECT_TYPE.PRODUCT,
8893
OBJECT_TYPE.TICKET,
8994
OBJECT_TYPE.LINE_ITEM,
95+
OBJECT_TYPE.LEAD,
9096
];
9197
const SEARCHABLE_OBJECT_TYPES = OBJECT_TYPES.filter(
9298
(type) => SEARCHABLE_OBJECT_TYPES_ARRAY.includes(type.value),
9399
);
94100

95-
const SEARCHABLE_OBJECT_PROPERTIES = {
96-
[OBJECT_TYPE.COMPANY]: [
97-
"name",
98-
"domain",
99-
"createdate",
100-
"hs_lastmodifieddate",
101-
"hs_object_id",
102-
],
103-
[OBJECT_TYPE.CONTACT]: [
104-
"firstname",
105-
"lastname",
106-
"email",
107-
"lastmodifieddate",
108-
"hs_object_id",
109-
"createdate",
110-
],
111-
[OBJECT_TYPE.DEAL]: [
112-
"dealname",
113-
"amount",
114-
"closedate",
115-
"pipeline",
116-
"dealstage",
117-
"createdate",
118-
"hs_lastmodifieddate",
119-
"hs_object_id",
120-
],
121-
[OBJECT_TYPE.FEEDBACK_SUBMISSION]: [
122-
"hs_createdate",
123-
"hs_lastmodifieddate",
124-
"hs_object_id",
125-
],
126-
[OBJECT_TYPE.PRODUCT]: [
127-
"name",
128-
"description",
129-
"price",
130-
"createdate",
131-
"hs_lastmodifieddate",
132-
"hs_object_id",
133-
],
134-
[OBJECT_TYPE.TICKET]: [
135-
"content",
136-
"hs_pipeline",
137-
"hs_pipeline_stage",
138-
"hs_ticket_category",
139-
"hs_ticket_priority",
140-
"subject",
141-
"createdate",
142-
"hs_lastmodifieddate",
143-
"hs_object_id",
144-
],
145-
[OBJECT_TYPE.LINE_ITEM]: [
146-
"quantity",
147-
"amount",
148-
"price",
149-
"createdate",
150-
"hs_lastmodifieddate",
151-
"hs_object_id",
152-
],
153-
};
154-
155101
const ENGAGEMENT_TYPES = [
156102
{
157103
label: "Note",
@@ -223,7 +169,6 @@ export {
223169
OBJECT_TYPES,
224170
HUBSPOT_OWNER,
225171
SEARCHABLE_OBJECT_TYPES,
226-
SEARCHABLE_OBJECT_PROPERTIES,
227172
ENGAGEMENT_TYPES,
228173
EMAIL_EVENT_TYPES,
229174
};

components/hubspot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/hubspot",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"description": "Pipedream Hubspot Components",
55
"main": "hubspot.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)