Skip to content

Commit 2f0931e

Browse files
committed
wip
1 parent b0720aa commit 2f0931e

File tree

10 files changed

+456
-2
lines changed

10 files changed

+456
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import common from "../../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "highlevel_oauth-create-record",
6+
name: "Create Record",
7+
description: "Creates a custom object record. [See the documentation](https://highlevel.stoplight.io/docs/integrations/47e05e18c5d41-create-record)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
schemaKey: {
13+
propDefinition: [
14+
common.props.app,
15+
"schemaKey",
16+
],
17+
reloadProps: true,
18+
},
19+
ownerId: {
20+
propDefinition: [
21+
common.props.app,
22+
"userId",
23+
],
24+
label: "Owner ID",
25+
description: "The ID of a user representing the owner of the record",
26+
optional: true,
27+
},
28+
followerIds: {
29+
propDefinition: [
30+
common.props.app,
31+
"userId",
32+
],
33+
type: "string[]",
34+
label: "Follower IDs",
35+
description: "An array of user IDs representing followers of the record",
36+
optional: true,
37+
},
38+
},
39+
async additionalProps() {
40+
const props = {};
41+
/* if (!this.schemaKey) {
42+
return props;
43+
}
44+
const { fields } = await this.app.getObject({
45+
schmeaKey: this.schemaKey,
46+
});
47+
for (const field of fields) {
48+
49+
} */
50+
return props;
51+
},
52+
async run({ $ }) {
53+
const response = await this.app.createRecord({
54+
$,
55+
schemaKey: this.schemaKey,
56+
data: {
57+
locationId: this.app.getLocationId(),
58+
owners: [
59+
this.ownerId,
60+
],
61+
followers: this.followerIds,
62+
properties: {},
63+
},
64+
});
65+
$.export("$summary", `Successfully created record with ID: ${response.record.id}`);
66+
return response;
67+
},
68+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import common from "../../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "highlevel_oauth-update-note",
6+
name: "Update Note",
7+
description: "Updates a note associated with a contact. [See the documentation](https://highlevel.stoplight.io/docs/integrations/71814e115658f-update-note)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
contactId: {
13+
propDefinition: [
14+
common.props.app,
15+
"contactId",
16+
],
17+
description: "The contact that the note is associated with",
18+
},
19+
noteId: {
20+
propDefinition: [
21+
common.props.app,
22+
"noteId",
23+
(c) => ({
24+
contactId: c.contactId,
25+
}),
26+
],
27+
},
28+
body: {
29+
type: "string",
30+
label: "Body",
31+
description: "The body of the note",
32+
},
33+
},
34+
async run({ $ }) {
35+
const response = await this.app.updateNote({
36+
$,
37+
contactId: this.contactId,
38+
noteId: this.noteId,
39+
data: {
40+
body: this.body,
41+
},
42+
});
43+
$.export("$summary", `Successfully updated note (ID: ${this.noteId})`);
44+
return response;
45+
},
46+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import common from "../../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "highlevel_oauth-update-record",
6+
name: "Update Record",
7+
description: "Updates a custom object record. [See the documentation](https://highlevel.stoplight.io/docs/integrations/b4c5fdbd3ec85-update-record)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
schemaKey: {
13+
propDefinition: [
14+
common.props.app,
15+
"schemaKey",
16+
],
17+
reloadProps: true,
18+
},
19+
},
20+
async additionalProps() {
21+
/* const props = {};
22+
if (!this.schemaKey) {
23+
return props;
24+
}
25+
const { fields } = await this.app.getObject({
26+
schmeaKey: this.schemaKey,
27+
});
28+
for (const field of fields) {
29+
30+
}
31+
return props; */
32+
},
33+
async run({ $ }) {
34+
const response = await this.app.updateRecord({
35+
$,
36+
});
37+
$.export("$summary", `Successfully updated record with ID: ${response.record.id}`);
38+
return response;
39+
},
40+
};

components/highlevel_oauth/highlevel_oauth.app.mjs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,58 @@ export default {
4949
})) || [];
5050
},
5151
},
52+
noteId: {
53+
type: "string",
54+
label: "Note ID",
55+
description: "The ID of the note to update",
56+
async options({ contactId }) {
57+
const { notes } = await this.listNotes({
58+
contactId,
59+
});
60+
return notes?.map(({
61+
id: value, body,
62+
}) => ({
63+
label: body.slice(0, 50),
64+
value,
65+
})) || [];
66+
},
67+
},
68+
userId: {
69+
type: "string",
70+
label: "User ID",
71+
description: "The ID of a user",
72+
async options() {
73+
const { users } = await this.listNotes({
74+
params: {
75+
locationId: this.getLocationId(),
76+
},
77+
});
78+
return users?.map(({
79+
id, name, email,
80+
}) => ({
81+
label: name ?? email ?? id,
82+
value: id,
83+
}));
84+
},
85+
},
86+
schemaKey: {
87+
type: "string",
88+
label: "Object Schema Key",
89+
description: "Key used to refer the custom / standard Object internally (lowercase + underscore_separated)",
90+
async options() {
91+
const { objects } = await this.listObjects({
92+
params: {
93+
locationId: this.getLocationId(),
94+
},
95+
});
96+
return objects?.map(({
97+
key: value, labels,
98+
}) => ({
99+
label: labels.plural,
100+
value,
101+
})) || [];
102+
},
103+
},
52104
},
53105
methods: {
54106
getLocationId() {
@@ -113,6 +165,61 @@ export default {
113165
...args,
114166
});
115167
},
168+
listNotes({
169+
contactId, ...args
170+
}) {
171+
return this._makeRequest({
172+
url: `/contacts/${contactId}/notes`,
173+
...args,
174+
});
175+
},
176+
getObject({
177+
schemaKey, ...args
178+
}) {
179+
return this._makeRequest({
180+
url: `/objects/${schemaKey}`,
181+
...args,
182+
});
183+
},
184+
listObjects(args = {}) {
185+
return this._makeRequest({
186+
url: "/objects",
187+
...args,
188+
});
189+
},
190+
listUsers(args = {}) {
191+
return this._makeRequest({
192+
url: "/users",
193+
...args,
194+
});
195+
},
196+
updateNote({
197+
contactId, noteId, ...args
198+
}) {
199+
return this._makeRequest({
200+
method: "PUT",
201+
url: `/contacts/${contactId}/notes/${noteId}`,
202+
...args,
203+
});
204+
},
205+
createRecord({
206+
schemaKey, ...args
207+
}) {
208+
return this._makeRequest({
209+
method: "POST",
210+
url: `/objects/${schemaKey}/records`,
211+
...args,
212+
});
213+
},
214+
updateRecord({
215+
schemaKey, recordId, ...args
216+
}) {
217+
return this._makeRequest({
218+
method: "PUT",
219+
url: `/objects/${schemaKey}/records/${recordId}`,
220+
...args,
221+
});
222+
},
116223
addContactToCampaign({
117224
contactId, campaignId, ...args
118225
}) {

components/highlevel_oauth/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/highlevel_oauth",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Pipedream HighLevel (OAuth) Components",
55
"main": "highlevel_oauth.app.mjs",
66
"keywords": [
@@ -13,6 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3"
16+
"@pipedream/platform": "^3.0.3",
17+
"md5": "^2.3.0"
1718
}
1819
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import common from "../common/base-polling.mjs";
2+
import md5 from "md5";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
...common,
7+
key: "highlevel_oauth-contact-updated",
8+
name: "Contact Updated",
9+
description: "Emit new event when an existing contact is updated. [See the documentation](https://highlevel.stoplight.io/docs/integrations/ab55933a57f6f-get-contacts)",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
methods: {
14+
...common.methods,
15+
_getContactValues() {
16+
return this.db.get("contactValues") || {};
17+
},
18+
_setContactValues(contactValues) {
19+
this.db.set("contactValues", contactValues);
20+
},
21+
generateMeta(contact) {
22+
const ts = Date.now();
23+
return {
24+
id: `${contact.id}${ts}`,
25+
summary: `Contact Updated w/ ID: ${contact.id}`,
26+
ts,
27+
};
28+
},
29+
},
30+
async run() {
31+
const results = [];
32+
const params = {
33+
limit: 100,
34+
locationId: this.app.getLocationId(),
35+
};
36+
let total;
37+
const contactValues = this._getContactValues();
38+
const newContactValues = {};
39+
40+
do {
41+
const {
42+
contacts, meta,
43+
} = await this.app.searchContacts({
44+
params,
45+
});
46+
for (const contact of contacts) {
47+
const hash = md5(JSON.stringify(contact));
48+
if (contactValues[contact.id] && contactValues[contact.id] !== hash) {
49+
results.push(contact);
50+
}
51+
newContactValues[contact.id] = hash;
52+
}
53+
params.startAfter = meta?.startAfter;
54+
total = meta?.total;
55+
} while (results.length < total);
56+
57+
results.forEach((contact) => {
58+
const meta = this.generateMeta(contact);
59+
this.$emit(contact, meta);
60+
});
61+
62+
this._setContactValues(newContactValues);
63+
},
64+
sampleEmit,
65+
};

0 commit comments

Comments
 (0)