-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Components] clarify - new components
- Loading branch information
Showing
15 changed files
with
717 additions
and
8 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
components/clarify/actions/create-company/create-company.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
components/clarify/actions/update-person/update-person.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
Oops, something went wrong.