Skip to content

Commit

Permalink
[Components] clarify - new components
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes committed Nov 28, 2024
1 parent b920895 commit a116ec0
Show file tree
Hide file tree
Showing 15 changed files with 717 additions and 8 deletions.
70 changes: 70 additions & 0 deletions components/clarify/actions/create-company/create-company.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import app from "../../clarify.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "clarify-create-company",
name: "Create Company",
description: "Creates a new company record in the Clarify system. [See the documentation](https://api.getclarify.ai/swagger#/default/createRecord).",
version: "0.0.1",
type: "action",
props: {
app,
workspace: {
propDefinition: [
app,
"workspace",
],
},
name: {
propDefinition: [
app,
"companyName",
],
},
domain: {
propDefinition: [
app,
"companyDomain",
],
},
},
methods: {
createCompany({
workspace, ...args
} = {}) {
return this.app.post({
path: `/workspaces/${workspace}/objects/${constants.OBJECT_ENTITY.COMPANY}/records`,
...args,
});
},
},
async run({ $ }) {
const {
createCompany,
workspace,
name,
domain,
} = this;

const response = await createCompany({
$,
workspace,
data: {
data: {
type: "object",
attributes: {
name,
domains: {
items: [
domain,
],
},
},
},
},
});

$.export("$summary", "Successfully created company.");
return response;
},
};
79 changes: 79 additions & 0 deletions components/clarify/actions/find-user/find-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import app from "../../clarify.app.mjs";

export default {
key: "clarify-find-user",
name: "Find User",
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).",
version: "0.0.1",
type: "action",
props: {
app,
workspace: {
propDefinition: [
app,
"workspace",
],
},
email: {
type: "string",
label: "Email",
description: "The email of the user to search for.",
},
firstName: {
type: "string",
label: "First Name",
description: "The first name of the user to search for.",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the user to search for.",
optional: true,
},
},
methods: {
getUsers({
workspace, ...args
} = {}) {
return this.app._makeRequest({
path: `/workspaces/${workspace}/users`,
...args,
});
},
},
async run({ $ }) {
const {
getUsers,
workspace,
email,
firstName,
lastName,
} = this;

const response = await getUsers({
$,
workspace,
params: {
limit: 1000,
},
});

const userFound = response.data.find(({ attributes }) =>
attributes.email === email
|| attributes.firstName?.toLowerCase()?.includes(firstName?.toLowerCase())
|| attributes.lastName?.toLowerCase()?.includes(lastName?.toLowerCase())
|| attributes?.name?.first_name?.toLowerCase()?.includes(firstName?.toLowerCase())
|| attributes?.name?.last_name?.toLowerCase()?.includes(lastName?.toLowerCase()));

if (!userFound) {
$.export("$summary", "No user found with the given attributes.");
return {
success: false,
};
}

$.export("$summary", "Successfully found user.");
return userFound;
},
};
72 changes: 72 additions & 0 deletions components/clarify/actions/update-person/update-person.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import app from "../../clarify.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "clarify-update-person",
name: "Update Person",
description: "Updates an existing person record in the Clarify system. [See the documentation](https://api.getclarify.ai/swagger#/default/updateRecord).",
version: "0.0.1",
type: "action",
props: {
app,
workspace: {
propDefinition: [
app,
"workspace",
],
},
personId: {
propDefinition: [
app,
"personId",
({ workspace }) => ({
workspace,
}),
],
},
companyId: {
propDefinition: [
app,
"companyId",
({ workspace }) => ({
workspace,
}),
],
},
},
methods: {
updatePerson({
workspace, personId, ...args
}) {
return this.app.patch({
path: `/workspaces/${workspace}/objects/${constants.OBJECT_ENTITY.PERSON}/records/${personId}`,
...args,
});
},
},
async run({ $ }) {
const {
updatePerson,
workspace,
personId,
companyId,
} = this;

const response = await updatePerson({
$,
workspace,
personId,
data: {
data: {
type: "object",
attributes: {
companyId,
},
},
},
});

$.export("$summary", "Successfully updated person.");
return response;
},
};
Loading

0 comments on commit a116ec0

Please sign in to comment.