Skip to content

Commit a116ec0

Browse files
committed
[Components] clarify - new components
1 parent b920895 commit a116ec0

File tree

15 files changed

+717
-8
lines changed

15 files changed

+717
-8
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import app from "../../clarify.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "clarify-create-company",
6+
name: "Create Company",
7+
description: "Creates a new company record in the Clarify system. [See the documentation](https://api.getclarify.ai/swagger#/default/createRecord).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
workspace: {
13+
propDefinition: [
14+
app,
15+
"workspace",
16+
],
17+
},
18+
name: {
19+
propDefinition: [
20+
app,
21+
"companyName",
22+
],
23+
},
24+
domain: {
25+
propDefinition: [
26+
app,
27+
"companyDomain",
28+
],
29+
},
30+
},
31+
methods: {
32+
createCompany({
33+
workspace, ...args
34+
} = {}) {
35+
return this.app.post({
36+
path: `/workspaces/${workspace}/objects/${constants.OBJECT_ENTITY.COMPANY}/records`,
37+
...args,
38+
});
39+
},
40+
},
41+
async run({ $ }) {
42+
const {
43+
createCompany,
44+
workspace,
45+
name,
46+
domain,
47+
} = this;
48+
49+
const response = await createCompany({
50+
$,
51+
workspace,
52+
data: {
53+
data: {
54+
type: "object",
55+
attributes: {
56+
name,
57+
domains: {
58+
items: [
59+
domain,
60+
],
61+
},
62+
},
63+
},
64+
},
65+
});
66+
67+
$.export("$summary", "Successfully created company.");
68+
return response;
69+
},
70+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import app from "../../clarify.app.mjs";
2+
3+
export default {
4+
key: "clarify-find-user",
5+
name: "Find User",
6+
description: "Searches within the Clarify system for a user based on the given 'email' prop. Returns the found user. [See the documentation](https://api.getclarify.ai/swagger#/default/getUsers).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
workspace: {
12+
propDefinition: [
13+
app,
14+
"workspace",
15+
],
16+
},
17+
email: {
18+
type: "string",
19+
label: "Email",
20+
description: "The email of the user to search for.",
21+
},
22+
firstName: {
23+
type: "string",
24+
label: "First Name",
25+
description: "The first name of the user to search for.",
26+
optional: true,
27+
},
28+
lastName: {
29+
type: "string",
30+
label: "Last Name",
31+
description: "The last name of the user to search for.",
32+
optional: true,
33+
},
34+
},
35+
methods: {
36+
getUsers({
37+
workspace, ...args
38+
} = {}) {
39+
return this.app._makeRequest({
40+
path: `/workspaces/${workspace}/users`,
41+
...args,
42+
});
43+
},
44+
},
45+
async run({ $ }) {
46+
const {
47+
getUsers,
48+
workspace,
49+
email,
50+
firstName,
51+
lastName,
52+
} = this;
53+
54+
const response = await getUsers({
55+
$,
56+
workspace,
57+
params: {
58+
limit: 1000,
59+
},
60+
});
61+
62+
const userFound = response.data.find(({ attributes }) =>
63+
attributes.email === email
64+
|| attributes.firstName?.toLowerCase()?.includes(firstName?.toLowerCase())
65+
|| attributes.lastName?.toLowerCase()?.includes(lastName?.toLowerCase())
66+
|| attributes?.name?.first_name?.toLowerCase()?.includes(firstName?.toLowerCase())
67+
|| attributes?.name?.last_name?.toLowerCase()?.includes(lastName?.toLowerCase()));
68+
69+
if (!userFound) {
70+
$.export("$summary", "No user found with the given attributes.");
71+
return {
72+
success: false,
73+
};
74+
}
75+
76+
$.export("$summary", "Successfully found user.");
77+
return userFound;
78+
},
79+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import app from "../../clarify.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "clarify-update-person",
6+
name: "Update Person",
7+
description: "Updates an existing person record in the Clarify system. [See the documentation](https://api.getclarify.ai/swagger#/default/updateRecord).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
workspace: {
13+
propDefinition: [
14+
app,
15+
"workspace",
16+
],
17+
},
18+
personId: {
19+
propDefinition: [
20+
app,
21+
"personId",
22+
({ workspace }) => ({
23+
workspace,
24+
}),
25+
],
26+
},
27+
companyId: {
28+
propDefinition: [
29+
app,
30+
"companyId",
31+
({ workspace }) => ({
32+
workspace,
33+
}),
34+
],
35+
},
36+
},
37+
methods: {
38+
updatePerson({
39+
workspace, personId, ...args
40+
}) {
41+
return this.app.patch({
42+
path: `/workspaces/${workspace}/objects/${constants.OBJECT_ENTITY.PERSON}/records/${personId}`,
43+
...args,
44+
});
45+
},
46+
},
47+
async run({ $ }) {
48+
const {
49+
updatePerson,
50+
workspace,
51+
personId,
52+
companyId,
53+
} = this;
54+
55+
const response = await updatePerson({
56+
$,
57+
workspace,
58+
personId,
59+
data: {
60+
data: {
61+
type: "object",
62+
attributes: {
63+
companyId,
64+
},
65+
},
66+
},
67+
});
68+
69+
$.export("$summary", "Successfully updated person.");
70+
return response;
71+
},
72+
};

0 commit comments

Comments
 (0)