Skip to content

Commit cbafd3d

Browse files
committed
new components
1 parent 2f0931e commit cbafd3d

File tree

5 files changed

+153
-38
lines changed

5 files changed

+153
-38
lines changed

components/highlevel_oauth/actions/create-record/create-record.mjs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import common from "../../common/base.mjs";
2+
import { parseObjectEntries } from "../../common/utils.mjs";
23

34
export default {
45
...common,
56
key: "highlevel_oauth-create-record",
67
name: "Create Record",
78
description: "Creates a custom object record. [See the documentation](https://highlevel.stoplight.io/docs/integrations/47e05e18c5d41-create-record)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
...common.props,
@@ -14,15 +15,14 @@ export default {
1415
common.props.app,
1516
"schemaKey",
1617
],
17-
reloadProps: true,
1818
},
1919
ownerId: {
2020
propDefinition: [
2121
common.props.app,
2222
"userId",
2323
],
2424
label: "Owner ID",
25-
description: "The ID of a user representing the owner of the record",
25+
description: "The ID of a user representing the owner of the record. Only supported for custom objects.",
2626
optional: true,
2727
},
2828
followerIds: {
@@ -32,22 +32,15 @@ export default {
3232
],
3333
type: "string[]",
3434
label: "Follower IDs",
35-
description: "An array of user IDs representing followers of the record",
35+
description: "An array of user IDs representing followers of the record. Only supported for custom objects",
3636
optional: true,
3737
},
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;
38+
properties: {
39+
propDefinition: [
40+
common.props.app,
41+
"properties",
42+
],
43+
},
5144
},
5245
async run({ $ }) {
5346
const response = await this.app.createRecord({
@@ -59,7 +52,7 @@ export default {
5952
this.ownerId,
6053
],
6154
followers: this.followerIds,
62-
properties: {},
55+
properties: parseObjectEntries(this.properties),
6356
},
6457
});
6558
$.export("$summary", `Successfully created record with ID: ${response.record.id}`);

components/highlevel_oauth/actions/update-record/update-record.mjs

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import common from "../../common/base.mjs";
2+
import { parseObjectEntries } from "../../common/utils.mjs";
23

34
export default {
45
...common,
56
key: "highlevel_oauth-update-record",
67
name: "Update Record",
78
description: "Updates a custom object record. [See the documentation](https://highlevel.stoplight.io/docs/integrations/b4c5fdbd3ec85-update-record)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
1112
...common.props,
@@ -14,25 +15,55 @@ export default {
1415
common.props.app,
1516
"schemaKey",
1617
],
17-
reloadProps: true,
1818
},
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; */
19+
recordId: {
20+
propDefinition: [
21+
common.props.app,
22+
"recordId",
23+
(c) => ({
24+
schemaKey: c.schemaKey,
25+
}),
26+
],
27+
},
28+
ownerId: {
29+
propDefinition: [
30+
common.props.app,
31+
"userId",
32+
],
33+
label: "Owner ID",
34+
description: "The ID of a user representing the owner of the record. Only supported for custom objects.",
35+
optional: true,
36+
},
37+
followerIds: {
38+
propDefinition: [
39+
common.props.app,
40+
"userId",
41+
],
42+
type: "string[]",
43+
label: "Follower IDs",
44+
description: "An array of user IDs representing followers of the record. Only supported for custom objects",
45+
optional: true,
46+
},
47+
properties: {
48+
propDefinition: [
49+
common.props.app,
50+
"properties",
51+
],
52+
},
3253
},
3354
async run({ $ }) {
3455
const response = await this.app.updateRecord({
3556
$,
57+
schemaKey: this.schemaKey,
58+
recordId: this.recordId,
59+
data: {
60+
locationId: this.app.getLocationId(),
61+
owners: [
62+
this.ownerId,
63+
],
64+
followers: this.followerIds,
65+
properties: parseObjectEntries(this.properties),
66+
},
3667
});
3768
$.export("$summary", `Successfully updated record with ID: ${response.record.id}`);
3869
return response;

components/highlevel_oauth/common/utils.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ function optionalParseAsJSON(value) {
77
}
88

99
export function parseObjectEntries(value) {
10+
if (!value) {
11+
return undefined;
12+
}
1013
const obj = typeof value === "string"
1114
? JSON.parse(value)
1215
: value;

components/highlevel_oauth/highlevel_oauth.app.mjs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
label: "User ID",
7171
description: "The ID of a user",
7272
async options() {
73-
const { users } = await this.listNotes({
73+
const { users } = await this.listUsers({
7474
params: {
7575
locationId: this.getLocationId(),
7676
},
@@ -86,7 +86,7 @@ export default {
8686
schemaKey: {
8787
type: "string",
8888
label: "Object Schema Key",
89-
description: "Key used to refer the custom / standard Object internally (lowercase + underscore_separated)",
89+
description: "Key used to refer the custom / standard Object internally. For custom objects, the key must include the “custom_objects.” prefix, while standard objects use their respective object keys. This information is available on the Custom Objects Details page under Settings.",
9090
async options() {
9191
const { objects } = await this.listObjects({
9292
params: {
@@ -101,6 +101,29 @@ export default {
101101
})) || [];
102102
},
103103
},
104+
recordId: {
105+
type: "string",
106+
label: "Record ID",
107+
description: "The ID of the record to be updated. Available on the Record details page under the 3 dots or in the url",
108+
async options({
109+
schemaKey, page,
110+
}) {
111+
const { customObjectRecords } = await this.searchRecords({
112+
schemaKey,
113+
params: {
114+
page: page + 1,
115+
pageLimit: 20,
116+
},
117+
});
118+
return customObjectRecords?.map(({ id }) => id) || [];
119+
},
120+
},
121+
properties: {
122+
type: "object",
123+
label: "Properties",
124+
description: "Properties of the record as key/value pairs. Example: `{\"customer_number\":1424,\"ticket_name\":\"Customer not able login\",\"phone_number\":\"+917000000000\"}`",
125+
optional: true,
126+
},
104127
},
105128
methods: {
106129
getLocationId() {
@@ -153,6 +176,15 @@ export default {
153176
...args,
154177
});
155178
},
179+
searchRecords({
180+
schemaKey, ...args
181+
}) {
182+
return this._makeRequest({
183+
method: "POST",
184+
url: `/objects/${schemaKey}/records/search`,
185+
...args,
186+
});
187+
},
156188
listCampaigns(args = {}) {
157189
return this._makeRequest({
158190
url: "/campaigns/",
@@ -183,13 +215,13 @@ export default {
183215
},
184216
listObjects(args = {}) {
185217
return this._makeRequest({
186-
url: "/objects",
218+
url: "/objects/",
187219
...args,
188220
});
189221
},
190222
listUsers(args = {}) {
191223
return this._makeRequest({
192-
url: "/users",
224+
url: "/users/",
193225
...args,
194226
});
195227
},
Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,70 @@
11
import common from "../common/base-polling.mjs";
2+
import md5 from "md5";
23

34
export default {
45
...common,
56
key: "highlevel_oauth-record-updated",
67
name: "Record Updated",
78
description: "Emit new event when a record is created or updated. [See the documentation](https://highlevel.stoplight.io/docs/integrations/0d0d041fb90fb-search-object-records)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "source",
1011
dedupe: "unique",
12+
props: {
13+
...common.props,
14+
schemaKey: {
15+
propDefinition: [
16+
common.props.app,
17+
"schemaKey",
18+
],
19+
},
20+
},
1121
methods: {
1222
...common.methods,
23+
_getRecordValues() {
24+
return this.db.get("recordValues") || {};
25+
},
26+
_setRecordValues(recordValues) {
27+
this.db.set("recordValues", recordValues);
28+
},
29+
generateMeta(record, createdOrUpdated) {
30+
const ts = Date.now();
31+
return {
32+
id: `${record.id}${ts}`,
33+
summary: `Record ${createdOrUpdated} w/ ID: ${record.id}`,
34+
ts,
35+
};
36+
},
37+
},
38+
async run() {
39+
const params = {
40+
page: 1,
41+
pageLimit: 100,
42+
locationId: this.app.getLocationId(),
43+
schemaKey: this.schemaKey,
44+
};
45+
let total;
46+
const recordValues = this._getRecordValues();
47+
const newRecordValues = {};
48+
49+
do {
50+
const { customObjectRecords } = await this.app.searchRecords({
51+
params,
52+
});
53+
for (const record of customObjectRecords) {
54+
const hash = md5(JSON.stringify(record));
55+
if (recordValues[record.id] !== hash) {
56+
const createOrUpdate = recordValues[record.id]
57+
? "Updated"
58+
: "Created";
59+
const meta = this.generateMeta(record, createOrUpdate);
60+
this.$emit(record, meta);
61+
}
62+
newRecordValues[record.id] = hash;
63+
}
64+
params.page++;
65+
total = customObjectRecords?.length;
66+
} while (total === params.pageLimit);
67+
68+
this._setRecordValues(newRecordValues);
1369
},
1470
};

0 commit comments

Comments
 (0)