Skip to content

Commit 3aea478

Browse files
committed
Merge branch 'master' into 14077-tricentis-new-components
2 parents d2901f9 + a72fc41 commit 3aea478

File tree

16 files changed

+845
-78
lines changed

16 files changed

+845
-78
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import hullo from "../../hullo.app.mjs";
2+
3+
export default {
4+
key: "hullo-add-update-member",
5+
name: "Add or Update Member",
6+
description: "Adds a new member or updates an existing member's data in Hullo. [See the documentation](https://app.hullo.me/docs/index.html#?route=post-/endpoints/members)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hullo,
11+
phoneNumber: {
12+
propDefinition: [
13+
hullo,
14+
"phoneNumber",
15+
],
16+
},
17+
fullName: {
18+
type: "string",
19+
label: "Full Name",
20+
description: "The full name of the member. REQUIRED if creating a new member.",
21+
optional: true,
22+
},
23+
registrationDate: {
24+
type: "string",
25+
label: "Registration Date",
26+
description: "The date the member was registered in ISO-8601 format. Example: `2000-01-23T04:56:07.000+00:00`",
27+
optional: true,
28+
},
29+
groups: {
30+
type: "string[]",
31+
label: "Groups",
32+
description: "An array containing the names of groups this member belongs to",
33+
optional: true,
34+
},
35+
attributes: {
36+
propDefinition: [
37+
hullo,
38+
"attributes",
39+
],
40+
reloadProps: true,
41+
},
42+
},
43+
async additionalProps() {
44+
const props = {};
45+
if (!this.attributes?.length) {
46+
return props;
47+
}
48+
for (const attribute of this.attributes) {
49+
props[attribute] = {
50+
type: "string",
51+
label: attribute,
52+
description: `Value for ${attribute}`,
53+
};
54+
}
55+
return props;
56+
},
57+
methods: {
58+
async formatAttributes(attributeKeys, attributeValues) {
59+
const attributes = await this.hullo.listAttributes();
60+
const formattedAttributes = {};
61+
for (const key of attributeKeys) {
62+
const { type } = attributes.find(({ name }) => name === key);
63+
const value = type === "NUMBER"
64+
? +attributeValues[key]
65+
: type === "LIST"
66+
? JSON.parse(attributeValues[key])
67+
: attributeValues[key];
68+
formattedAttributes[key] = [
69+
value,
70+
];
71+
}
72+
return formattedAttributes;
73+
},
74+
},
75+
async run({ $ }) {
76+
const {
77+
hullo,
78+
formatAttributes,
79+
phoneNumber,
80+
fullName,
81+
registrationDate,
82+
groups,
83+
attributes,
84+
...attributeValues
85+
} = this;
86+
87+
const response = await hullo.addOrUpdateMember({
88+
$,
89+
data: {
90+
phoneNumber,
91+
fullName,
92+
registrationDate,
93+
groups,
94+
attributes: attributes?.length
95+
? await formatAttributes(attributes, attributeValues)
96+
: undefined,
97+
},
98+
});
99+
$.export("$summary", `Successfully added or updated member with phone number ${this.phoneNumber}`);
100+
return response;
101+
},
102+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import hullo from "../../hullo.app.mjs";
2+
3+
export default {
4+
key: "hullo-send-message",
5+
name: "Send Message",
6+
description: "Sends a personalized message to a Hullo member. [See the documentation](https://app.hullo.me/docs/index.html#?route=post-/endpoints/messages)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hullo,
11+
phoneNumber: {
12+
propDefinition: [
13+
hullo,
14+
"phoneNumber",
15+
],
16+
},
17+
messageText: {
18+
type: "string",
19+
label: "Message Text",
20+
description: "The message text to send. Min length: 1, Max length: 640",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.hullo.sendMessage({
25+
$,
26+
data: {
27+
phoneNumber: this.phoneNumber,
28+
messageText: this.messageText,
29+
},
30+
});
31+
$.export("$summary", `Successfully sent message to member with phone number: ${this.phoneNumber}`);
32+
return response;
33+
},
34+
};

components/hullo/hullo.app.mjs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "hullo",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
attributes: {
8+
type: "string[]",
9+
label: "Attributes",
10+
description: "The attributes that describe the member",
11+
optional: true,
12+
async options() {
13+
const attributes = await this.listAttributes();
14+
return attributes?.map(({ name }) => name ) || [];
15+
},
16+
},
17+
phoneNumber: {
18+
type: "string",
19+
label: "Phone Number",
20+
description: "The phone number of the member",
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_baseUrl() {
25+
return "https://app.hullo.me/api/endpoints";
26+
},
27+
_makeRequest(opts = {}) {
28+
const {
29+
$ = this,
30+
path,
31+
...otherOpts
32+
} = opts;
33+
return axios($, {
34+
...otherOpts,
35+
url: `${this._baseUrl()}${path}`,
36+
headers: {
37+
"X-API-KEY": `${this.$auth.api_key}`,
38+
},
39+
});
40+
},
41+
listAttributes(opts = {}) {
42+
return this._makeRequest({
43+
path: "/attributes",
44+
...opts,
45+
});
46+
},
47+
sendMessage(opts = {}) {
48+
return this._makeRequest({
49+
method: "POST",
50+
path: "/messages",
51+
...opts,
52+
});
53+
},
54+
addOrUpdateMember(opts = {}) {
55+
return this._makeRequest({
56+
method: "POST",
57+
path: "/members",
58+
...opts,
59+
});
960
},
1061
},
1162
};

components/hullo/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/hullo",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Hullo Components",
55
"main": "hullo.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

components/smartsuite/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import smartsuite from "../../smartsuite.app.mjs";
2+
3+
export default {
4+
key: "smartsuite-create-record",
5+
name: "Create Record",
6+
description: "Creates a new record. [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/create-record)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
smartsuite,
11+
tableId: {
12+
propDefinition: [
13+
smartsuite,
14+
"tableId",
15+
],
16+
reloadProps: true,
17+
},
18+
},
19+
async additionalProps() {
20+
const props = {};
21+
if (!this.tableId) {
22+
return props;
23+
}
24+
const { structure: fields } = await this.smartsuite.listFields({
25+
tableId: this.tableId,
26+
});
27+
for (const field of fields) {
28+
if (!field.params.is_auto_generated
29+
&& !field.params.system
30+
&& field.field_type !== "linkedrecordfield"
31+
&& field.field_type !== "filefield"
32+
&& field.field_type !== "userfield"
33+
) {
34+
props[field.slug] = {
35+
type: "string",
36+
label: field.label,
37+
optional: !field.params.required,
38+
options: field.params.choices
39+
? field.params.choices.map(({
40+
value, label,
41+
}) => ({
42+
value,
43+
label,
44+
}))
45+
: undefined,
46+
};
47+
}
48+
}
49+
return props;
50+
},
51+
async run({ $ }) {
52+
const {
53+
smartsuite,
54+
tableId,
55+
...data
56+
} = this;
57+
58+
const response = await smartsuite.createRecord({
59+
$,
60+
tableId,
61+
data,
62+
});
63+
$.export("$summary", `Successfully created record with ID: ${response.id}`);
64+
return response;
65+
},
66+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import smartsuite from "../../smartsuite.app.mjs";
2+
3+
export default {
4+
key: "smartsuite-find-records",
5+
name: "Find Records",
6+
description: "Search for records based on matching field(s). [See the documentation](https://developers.smartsuite.com/docs/solution-data/records/list-records)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
smartsuite,
11+
tableId: {
12+
propDefinition: [
13+
smartsuite,
14+
"tableId",
15+
],
16+
},
17+
fieldIds: {
18+
propDefinition: [
19+
smartsuite,
20+
"fieldIds",
21+
(c) => ({
22+
tableId: c.tableId,
23+
}),
24+
],
25+
reloadProps: true,
26+
},
27+
},
28+
async additionalProps() {
29+
const props = {};
30+
if (!this.tableId || !this.fieldIds?.length) {
31+
return props;
32+
}
33+
const { structure: fields } = await this.smartsuite.listFields({
34+
tableId: this.tableId,
35+
});
36+
for (const fieldId of this.fieldIds) {
37+
const field = fields.find(({ slug }) => slug === fieldId);
38+
props[fieldId] = {
39+
type: "string",
40+
label: field.label,
41+
};
42+
}
43+
return props;
44+
},
45+
async run({ $ }) {
46+
const fields = this.fieldIds?.length
47+
? this.fieldIds.map((field) => ({
48+
comparison: "is",
49+
field,
50+
value: this[field],
51+
}))
52+
: undefined;
53+
const { items } = await this.smartsuite.listRecords({
54+
$,
55+
tableId: this.tableId,
56+
data: {
57+
filter: {
58+
operator: "and",
59+
fields,
60+
},
61+
},
62+
});
63+
if (items?.length) {
64+
$.export("$summary", `Successfully found ${items.length} record${items.length === 1
65+
? ""
66+
: "s"}`);
67+
}
68+
return items;
69+
},
70+
};

components/smartsuite/app/smartsuite.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)