Skip to content

Commit 0d5d83c

Browse files
authored
Hubspot actions - support end user auth (#14958)
* bug fix * support end user auth * package.json version * pnpm-lock.yaml * updates * updates
1 parent 1554545 commit 0d5d83c

File tree

19 files changed

+235
-110
lines changed

19 files changed

+235
-110
lines changed

components/hubspot/actions/common/common-create-object.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
propertyGroups: {
1010
type: "string[]",
1111
label: "Property Groups",
12+
hidden: true,
1213
reloadProps: true,
1314
async options() {
1415
const { results: groups } = await this.hubspot.getPropertyGroups({
@@ -20,6 +21,11 @@ export default {
2021
}));
2122
},
2223
},
24+
objectProperties: {
25+
type: "object",
26+
label: "Object Properties",
27+
description: "Enter the object properties to create as a JSON object",
28+
},
2329
},
2430
methods: {
2531
...common.methods,
@@ -46,10 +52,17 @@ export default {
4652
contactId,
4753
$db,
4854
updateIfExists,
49-
...properties
55+
objectProperties,
56+
...otherProperties
5057
} = this;
5158
const objectType = this.getObjectType();
5259

60+
const properties = objectProperties
61+
? typeof objectProperties === "string"
62+
? JSON.parse(objectProperties)
63+
: objectProperties
64+
: otherProperties;
65+
5366
// checkbox (string[]) props must be semicolon separated strings
5467
Object.keys(properties)
5568
.forEach((key) => {

components/hubspot/actions/common/common-create.mjs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import hubspot from "../../hubspot.app.mjs";
21
import {
32
OBJECT_TYPE, HUBSPOT_OWNER,
43
} from "../../common/constants.mjs";
4+
import appProp from "./common-app-prop.mjs";
55

66
/**
77
* Returns an options method for a CRM object type, intended to be used in
@@ -43,7 +43,7 @@ function getOptionsMethod(objectTypeName) {
4343

4444
export default {
4545
props: {
46-
hubspot,
46+
...appProp.props,
4747
},
4848
methods: {
4949
getObjectType() {
@@ -112,25 +112,51 @@ export default {
112112
};
113113
},
114114
},
115-
async additionalProps() {
115+
async additionalProps(existingProps) {
116116
const objectType = this.getObjectType();
117-
const schema = await this.hubspot.getSchema({
118-
objectType,
119-
});
120-
const { results: properties } = await this.hubspot.getProperties({
121-
objectType,
122-
});
123-
const relevantProperties = properties.filter(this.isRelevantProperty);
124-
const propDefinitions = [];
125-
for (const property of relevantProperties) {
126-
propDefinitions.push(await this.makePropDefinition(property, schema.requiredProperties));
117+
try {
118+
const schema = await this.hubspot.getSchema({
119+
objectType,
120+
});
121+
const { results: properties } = await this.hubspot.getProperties({
122+
objectType,
123+
});
124+
const relevantProperties = properties.filter(this.isRelevantProperty);
125+
126+
const propDefinitions = [];
127+
if (this.propertyGroups && !relevantProperties?.length) {
128+
propDefinitions.push({
129+
type: "alert",
130+
alertType: "info",
131+
name: "infoAlert",
132+
content: `No writable properties found for Property Group(s): ${this.propertyGroups.join(", ")}`,
133+
});
134+
}
135+
136+
for (const property of relevantProperties) {
137+
propDefinitions.push(await this.makePropDefinition(property, schema.requiredProperties));
138+
}
139+
140+
if (existingProps.objectProperties) {
141+
existingProps.objectProperties.hidden = true;
142+
existingProps.objectProperties.optional = true;
143+
}
144+
if (existingProps.propertyGroups) {
145+
existingProps.propertyGroups.hidden = false;
146+
}
147+
148+
return propDefinitions
149+
.reduce((props, {
150+
name, ...definition
151+
}) => {
152+
props[name] = definition;
153+
return props;
154+
}, {});
155+
} catch {
156+
if (existingProps.propertyGroups) {
157+
existingProps.propertyGroups.optional = true;
158+
}
159+
return {};
127160
}
128-
return propDefinitions
129-
.reduce((props, {
130-
name, ...definition
131-
}) => {
132-
props[name] = definition;
133-
return props;
134-
}, {});
135161
},
136162
};

components/hubspot/actions/common/common-update-object.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export default {
1919
}));
2020
},
2121
},
22+
objectProperties: {
23+
type: "object",
24+
label: "Object Properties",
25+
description: "Enter the object properties to update as a JSON object",
26+
},
2227
},
2328
methods: {
2429
...common.methods,
@@ -35,10 +40,17 @@ export default {
3540
customObjectType,
3641
$db,
3742
objectId,
38-
...properties
43+
objectProperties,
44+
...otherProperties
3945
} = this;
4046
const objectType = this.getObjectType();
4147

48+
const properties = objectProperties
49+
? typeof objectProperties === "string"
50+
? JSON.parse(objectProperties)
51+
: objectProperties
52+
: otherProperties;
53+
4254
// checkbox (string[]) props must be semicolon separated strings
4355
Object.keys(properties)
4456
.forEach((key) => {

components/hubspot/actions/create-communication/create-communication.mjs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import common from "../common/common-create.mjs";
2-
import appProp from "./common-app-prop.mjs";
2+
import appProp from "../common/common-app-prop.mjs";
33
import { ConfigurationError } from "@pipedream/platform";
44
import { ASSOCIATION_CATEGORY } from "../../common/constants.mjs";
55

@@ -8,7 +8,7 @@ export default {
88
key: "hubspot-create-communication",
99
name: "Create Communication",
1010
description: "Create a WhatsApp, LinkedIn, or SMS message. [See the documentation](https://developers.hubspot.com/beta-docs/reference/api/crm/engagements/communications/v3#post-%2Fcrm%2Fv3%2Fobjects%2Fcommunications)",
11-
version: "0.0.3",
11+
version: "0.0.4",
1212
type: "action",
1313
props: {
1414
...appProp.props,
@@ -45,6 +45,11 @@ export default {
4545
description: "A unique identifier to indicate the association type between the communication and the other object",
4646
optional: true,
4747
},
48+
objectProperties: {
49+
type: "object",
50+
label: "Object Properties",
51+
description: "Enter the `communication` properties as a JSON object",
52+
},
4853
},
4954
methods: {
5055
...common.methods,
@@ -60,13 +65,20 @@ export default {
6065
toObjectId,
6166
associationType,
6267
getObjectType,
63-
...properties
68+
objectProperties,
69+
...otherProperties
6470
} = this;
6571

6672
if ((toObjectId && !associationType) || (!toObjectId && associationType)) {
6773
throw new ConfigurationError("Both `toObjectId` and `associationType` must be entered");
6874
}
6975

76+
const properties = objectProperties
77+
? typeof objectProperties === "string"
78+
? JSON.parse(objectProperties)
79+
: objectProperties
80+
: otherProperties;
81+
7082
const response = await hubspot.createObject({
7183
$,
7284
objectType: getObjectType(),

components/hubspot/actions/create-company/create-company.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "hubspot-create-company",
77
name: "Create Company",
88
description: "Create a company in Hubspot. [See the documentation](https://developers.hubspot.com/docs/api/crm/companies#endpoint?spec=POST-/crm/v3/objects/companies)",
9-
version: "0.0.14",
9+
version: "0.0.15",
1010
type: "action",
1111
methods: {
1212
...common.methods,

components/hubspot/actions/create-custom-object/create-custom-object.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import hubspot from "../../hubspot.app.mjs";
21
import common from "../common/common-create-object.mjs";
2+
import appProp from "../common/common-app-prop.mjs";
33

44
export default {
55
...common,
66
key: "hubspot-create-custom-object",
77
name: "Create Custom Object",
88
description: "Create a new custom object in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/custom-objects#create-a-custom-object)",
9-
version: "0.0.2",
9+
version: "0.0.3",
1010
type: "action",
1111
props: {
12-
hubspot,
12+
...appProp.props,
1313
customObjectType: {
1414
propDefinition: [
15-
hubspot,
15+
appProp.props.hubspot,
1616
"customObjectType",
1717
],
1818
},

components/hubspot/actions/create-deal/create-deal.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "hubspot-create-deal",
77
name: "Create Deal",
88
description: "Create a deal in Hubspot. [See the documentation](https://developers.hubspot.com/docs/api/crm/deals#endpoint?spec=POST-/crm/v3/objects/deals)",
9-
version: "0.0.14",
9+
version: "0.0.15",
1010
type: "action",
1111
props: {
1212
...common.props,

components/hubspot/actions/create-engagement/create-engagement.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
key: "hubspot-create-engagement",
1010
name: "Create Engagement",
1111
description: "Create a new engagement for a contact. [See the documentation](https://developers.hubspot.com/docs/api/crm/engagements)",
12-
version: "0.0.13",
12+
version: "0.0.14",
1313
type: "action",
1414
props: {
1515
...common.props,
@@ -53,6 +53,11 @@ export default {
5353
description: "A unique identifier to indicate the association type between the task and the other object",
5454
optional: true,
5555
},
56+
objectProperties: {
57+
type: "object",
58+
label: "Object Properties",
59+
description: "Enter the `engagement` properties as a JSON object",
60+
},
5661
},
5762
methods: {
5863
...common.methods,
@@ -82,13 +87,20 @@ export default {
8287
toObjectId,
8388
associationType,
8489
$db,
85-
...properties
90+
objectProperties,
91+
...otherProperties
8692
} = this;
8793

8894
if ((toObjectId && !associationType) || (!toObjectId && associationType)) {
8995
throw new ConfigurationError("Both `toObjectId` and `associationType` must be entered");
9096
}
9197

98+
const properties = objectProperties
99+
? typeof objectProperties === "string"
100+
? JSON.parse(objectProperties)
101+
: objectProperties
102+
: otherProperties;
103+
92104
const objectType = this.getObjectType();
93105

94106
const associations = toObjectId

components/hubspot/actions/create-lead/create-lead.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import {
22
OBJECT_TYPE, ASSOCIATION_CATEGORY,
33
} from "../../common/constants.mjs";
44
import common from "../common/common-create-object.mjs";
5-
import hubspot from "../../hubspot.app.mjs";
5+
import appProp from "../common/common-app-prop.mjs";
66

77
export default {
88
...common,
99
key: "hubspot-create-lead",
1010
name: "Create Lead",
1111
description: "Create a lead in Hubspot. [See the documentation](https://developers.hubspot.com/beta-docs/guides/api/crm/objects/leads#create-leads)",
12-
version: "0.0.2",
12+
version: "0.0.3",
1313
type: "action",
1414
props: {
15-
hubspot,
15+
...appProp.props,
1616
contactId: {
1717
propDefinition: [
18-
hubspot,
18+
appProp.props.hubspot,
1919
"objectId",
2020
() => ({
2121
objectType: "contact",

0 commit comments

Comments
 (0)