-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - _1crm #12843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - _1crm #12843
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c91b41a
_1crm init
luancazarine fff5898
v1
luancazarine d9d0c3c
pnpm update
luancazarine 3c98dd9
[Components] 1crm #12758
luancazarine 7015c83
Merge branch 'master' into issue-12758
luancazarine 71d3e5d
fix test-event files
luancazarine 7a59268
Remove sources
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,11 +1,83 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import { LIMIT } from "./common/constants.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "_1crm", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
recordId: { | ||
type: "string", | ||
label: "Contact ID", | ||
description: "ID of the contact", | ||
async options({ | ||
page, model, | ||
}) { | ||
const { records } = await this.listModuleRecords({ | ||
module: model, | ||
params: { | ||
offset: LIMIT * page, | ||
limit: LIMIT, | ||
}, | ||
}); | ||
|
||
return records.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return `${this.$auth.url}/api.php`; | ||
}, | ||
_auth() { | ||
return { | ||
username: `${this.$auth.username}`, | ||
password: `${this.$auth.password}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
auth: this._auth(), | ||
...opts, | ||
}); | ||
}, | ||
getFields({ module }) { | ||
return this._makeRequest({ | ||
path: `/meta/fields/${module}`, | ||
}); | ||
}, | ||
listModuleRecords({ | ||
module, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/data/${module}`, | ||
...opts, | ||
}); | ||
}, | ||
createModel({ | ||
model, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/data/${model}`, | ||
...opts, | ||
}); | ||
}, | ||
updateModel({ | ||
updateId, model, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "PATCH", | ||
path: `/data/${model}/${updateId}`, | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains hidden or 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,106 @@ | ||
import _1crm from "../../_1crm.app.mjs"; | ||
|
||
export default { | ||
props: { | ||
_1crm, | ||
checkDuplicates: { | ||
type: "boolean", | ||
label: "Check Duplicates", | ||
description: "Check Duplicates Flag", | ||
default: true, | ||
reloadProps: true, | ||
}, | ||
}, | ||
methods: { | ||
getMethod() { | ||
return "create"; | ||
}, | ||
getUpdateId() { | ||
return ""; | ||
}, | ||
getType(type) { | ||
switch (type) { | ||
case "bool": return "boolean"; | ||
case "int": return "integer"; | ||
case "multienum": return "string[]"; | ||
default: return "string"; | ||
} | ||
}, | ||
filterFields(fields) { | ||
const groups = []; | ||
return Object.keys(fields) | ||
.filter( (key) => !("editable" in fields[key])) | ||
.filter( (key) => { | ||
if (fields[key].multi_select_group && !groups.includes(fields[key].multi_select_group)) { | ||
groups.push(fields[key].multi_select_group); | ||
return true; | ||
} | ||
if (!fields[key].multi_select_group ) return true; | ||
}) | ||
.reduce( (res, key) => (res[key] = fields[key], res), {} ); | ||
}, | ||
fixValues(data) { | ||
return Object.keys(data) | ||
.reduce( (res, key) => (res[key] = (typeof data[key] === "boolean" | ||
? +data[key] | ||
: (Array.isArray(data[key])) | ||
? data[key].join(",") | ||
: data[key]), res), {} ); | ||
}, | ||
}, | ||
async additionalProps() { | ||
const method = this.getMethod(); | ||
const props = {}; | ||
let { fields } = await this._1crm.getFields({ | ||
module: this.getModule(), | ||
}); | ||
delete fields.assigned_user; | ||
delete fields.assigned_user_id; | ||
|
||
fields = this.filterFields(fields); | ||
|
||
for (const [ | ||
key, | ||
value, | ||
] of Object.entries(fields)) { | ||
props[key] = { | ||
type: this.getType(value.type), | ||
label: value.vname, | ||
description: value.comment, | ||
optional: (method === "create") | ||
? !value.required | ||
: true, | ||
options: value.options, | ||
}; | ||
} | ||
return props; | ||
}, | ||
async run({ $ }) { | ||
const { | ||
_1crm, | ||
checkDuplicates, | ||
...data | ||
} = this; | ||
|
||
const method = this.getMethod(); | ||
const fn = (method === "create") | ||
? _1crm.createModel | ||
: _1crm.updateModel; | ||
|
||
const response = await fn({ | ||
$, | ||
data: { | ||
data: this.fixValues(data), | ||
}, | ||
params: { | ||
check_duplicates: checkDuplicates, | ||
}, | ||
updateId: this.getUpdateId(), | ||
model: this.getModule(), | ||
}); | ||
if (response.errors) throw new Error(response.errors); | ||
|
||
$.export("$summary", this.getSummary(response)); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return response; | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
components/_1crm/actions/create-contact/create-contact.mjs
This file contains hidden or 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,19 @@ | ||
import common from "../common/base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "_1crm-create-contact", | ||
name: "Create Contact", | ||
description: "Creates a new contact in the 1CRM system. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataList_post)", | ||
version: "0.0.1", | ||
type: "action", | ||
methods: { | ||
...common.methods, | ||
getModule() { | ||
return "Contact"; | ||
}, | ||
getSummary({ id }) { | ||
return `Successfully created contact with ID ${id}`; | ||
}, | ||
}, | ||
}; |
This file contains hidden or 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,19 @@ | ||
import common from "../common/base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "_1crm-create-lead", | ||
name: "Create Lead", | ||
description: "Crafts a new lead in 1CRM. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataList_post)", | ||
version: "0.0.1", | ||
type: "action", | ||
methods: { | ||
...common.methods, | ||
getModule() { | ||
return "Lead"; | ||
}, | ||
getSummary({ id }) { | ||
return `Successfully created lead with ID ${id}`; | ||
}, | ||
}, | ||
}; |
34 changes: 34 additions & 0 deletions
34
components/_1crm/actions/update-contact/update-contact.mjs
This file contains hidden or 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,34 @@ | ||
import common from "../create-contact/create-contact.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "_1crm-update-contact", | ||
name: "Update Contact", | ||
description: "Modifies an existing contact within the 1CRM system. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataRecord_patch)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
contactId: { | ||
propDefinition: [ | ||
common.props._1crm, | ||
"recordId", | ||
() => ({ | ||
model: "Contact", | ||
}), | ||
], | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
getMethod() { | ||
return "update"; | ||
}, | ||
getUpdateId() { | ||
return this.contactId; | ||
}, | ||
getSummary() { | ||
return `Successfully updated contact with ID ${this.contactId}`; | ||
}, | ||
}, | ||
}; |
This file contains hidden or 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,36 @@ | ||
import common from "../create-lead/create-lead.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "_1crm-update-lead", | ||
name: "Update Lead", | ||
description: "Updates an existing lead in 1CRM. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataRecord_patch)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
leadId: { | ||
propDefinition: [ | ||
common.props._1crm, | ||
"recordId", | ||
() => ({ | ||
model: "Lead", | ||
}), | ||
], | ||
label: "Lead ID", | ||
description: "ID of the lead", | ||
}, | ||
}, | ||
methods: { | ||
...common.methods, | ||
getMethod() { | ||
return "update"; | ||
}, | ||
getUpdateId() { | ||
return this.leadId; | ||
}, | ||
getSummary() { | ||
return `Lead with ID ${this.leadId} updated successfully`; | ||
}, | ||
}, | ||
}; |
This file contains hidden or 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 @@ | ||
export const LIMIT = 100; |
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/_1crm", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream 1CRM Components", | ||
"main": "_1crm.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.0" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.