Skip to content

Commit 241de66

Browse files
authored
New Components - _1crm (#12843)
* _1crm init * v1 * pnpm update * [Components] 1crm #12758 Sources - New Or Updated Account (Instant) - New Or Updated Invoice (Instant) - New Or Updated Lead (Instant) Actions - Create Contact - Update Contact - Create Load - Update Load * fix test-event files * Remove sources
1 parent 34d6ce6 commit 241de66

File tree

10 files changed

+386
-8
lines changed

10 files changed

+386
-8
lines changed

components/_1crm/_1crm.app.mjs

+77-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "_1crm",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
recordId: {
9+
type: "string",
10+
label: "Contact ID",
11+
description: "ID of the contact",
12+
async options({
13+
page, model,
14+
}) {
15+
const { records } = await this.listModuleRecords({
16+
module: model,
17+
params: {
18+
offset: LIMIT * page,
19+
limit: LIMIT,
20+
},
21+
});
22+
23+
return records.map(({
24+
id: value, name: label,
25+
}) => ({
26+
label,
27+
value,
28+
}));
29+
},
30+
},
31+
},
532
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
33+
_baseUrl() {
34+
return `${this.$auth.url}/api.php`;
35+
},
36+
_auth() {
37+
return {
38+
username: `${this.$auth.username}`,
39+
password: `${this.$auth.password}`,
40+
};
41+
},
42+
_makeRequest({
43+
$ = this, path, ...opts
44+
}) {
45+
return axios($, {
46+
url: this._baseUrl() + path,
47+
auth: this._auth(),
48+
...opts,
49+
});
50+
},
51+
getFields({ module }) {
52+
return this._makeRequest({
53+
path: `/meta/fields/${module}`,
54+
});
55+
},
56+
listModuleRecords({
57+
module, ...opts
58+
}) {
59+
return this._makeRequest({
60+
path: `/data/${module}`,
61+
...opts,
62+
});
63+
},
64+
createModel({
65+
model, ...opts
66+
}) {
67+
return this._makeRequest({
68+
method: "POST",
69+
path: `/data/${model}`,
70+
...opts,
71+
});
72+
},
73+
updateModel({
74+
updateId, model, ...opts
75+
}) {
76+
return this._makeRequest({
77+
method: "PATCH",
78+
path: `/data/${model}/${updateId}`,
79+
...opts,
80+
});
981
},
1082
},
11-
};
83+
};
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import _1crm from "../../_1crm.app.mjs";
2+
3+
export default {
4+
props: {
5+
_1crm,
6+
checkDuplicates: {
7+
type: "boolean",
8+
label: "Check Duplicates",
9+
description: "Check Duplicates Flag",
10+
default: true,
11+
reloadProps: true,
12+
},
13+
},
14+
methods: {
15+
getMethod() {
16+
return "create";
17+
},
18+
getUpdateId() {
19+
return "";
20+
},
21+
getType(type) {
22+
switch (type) {
23+
case "bool": return "boolean";
24+
case "int": return "integer";
25+
case "multienum": return "string[]";
26+
default: return "string";
27+
}
28+
},
29+
filterFields(fields) {
30+
const groups = [];
31+
return Object.keys(fields)
32+
.filter( (key) => !("editable" in fields[key]))
33+
.filter( (key) => {
34+
if (fields[key].multi_select_group && !groups.includes(fields[key].multi_select_group)) {
35+
groups.push(fields[key].multi_select_group);
36+
return true;
37+
}
38+
if (!fields[key].multi_select_group ) return true;
39+
})
40+
.reduce( (res, key) => (res[key] = fields[key], res), {} );
41+
},
42+
fixValues(data) {
43+
return Object.keys(data)
44+
.reduce( (res, key) => (res[key] = (typeof data[key] === "boolean"
45+
? +data[key]
46+
: (Array.isArray(data[key]))
47+
? data[key].join(",")
48+
: data[key]), res), {} );
49+
},
50+
},
51+
async additionalProps() {
52+
const method = this.getMethod();
53+
const props = {};
54+
let { fields } = await this._1crm.getFields({
55+
module: this.getModule(),
56+
});
57+
delete fields.assigned_user;
58+
delete fields.assigned_user_id;
59+
60+
fields = this.filterFields(fields);
61+
62+
for (const [
63+
key,
64+
value,
65+
] of Object.entries(fields)) {
66+
props[key] = {
67+
type: this.getType(value.type),
68+
label: value.vname,
69+
description: value.comment,
70+
optional: (method === "create")
71+
? !value.required
72+
: true,
73+
options: value.options,
74+
};
75+
}
76+
return props;
77+
},
78+
async run({ $ }) {
79+
const {
80+
_1crm,
81+
checkDuplicates,
82+
...data
83+
} = this;
84+
85+
const method = this.getMethod();
86+
const fn = (method === "create")
87+
? _1crm.createModel
88+
: _1crm.updateModel;
89+
90+
const response = await fn({
91+
$,
92+
data: {
93+
data: this.fixValues(data),
94+
},
95+
params: {
96+
check_duplicates: checkDuplicates,
97+
},
98+
updateId: this.getUpdateId(),
99+
model: this.getModule(),
100+
});
101+
if (response.errors) throw new Error(response.errors);
102+
103+
$.export("$summary", this.getSummary(response));
104+
return response;
105+
},
106+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "_1crm-create-contact",
6+
name: "Create Contact",
7+
description: "Creates a new contact in the 1CRM system. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataList_post)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
...common.methods,
12+
getModule() {
13+
return "Contact";
14+
},
15+
getSummary({ id }) {
16+
return `Successfully created contact with ID ${id}`;
17+
},
18+
},
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "_1crm-create-lead",
6+
name: "Create Lead",
7+
description: "Crafts a new lead in 1CRM. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataList_post)",
8+
version: "0.0.1",
9+
type: "action",
10+
methods: {
11+
...common.methods,
12+
getModule() {
13+
return "Lead";
14+
},
15+
getSummary({ id }) {
16+
return `Successfully created lead with ID ${id}`;
17+
},
18+
},
19+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import common from "../create-contact/create-contact.mjs";
2+
3+
export default {
4+
...common,
5+
key: "_1crm-update-contact",
6+
name: "Update Contact",
7+
description: "Modifies an existing contact within the 1CRM system. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataRecord_patch)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
contactId: {
13+
propDefinition: [
14+
common.props._1crm,
15+
"recordId",
16+
() => ({
17+
model: "Contact",
18+
}),
19+
],
20+
},
21+
},
22+
methods: {
23+
...common.methods,
24+
getMethod() {
25+
return "update";
26+
},
27+
getUpdateId() {
28+
return this.contactId;
29+
},
30+
getSummary() {
31+
return `Successfully updated contact with ID ${this.contactId}`;
32+
},
33+
},
34+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import common from "../create-lead/create-lead.mjs";
2+
3+
export default {
4+
...common,
5+
key: "_1crm-update-lead",
6+
name: "Update Lead",
7+
description: "Updates an existing lead in 1CRM. [See the documentation](https://demo.1crmcloud.com/api.php#endpoint_dataRecord_patch)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
leadId: {
13+
propDefinition: [
14+
common.props._1crm,
15+
"recordId",
16+
() => ({
17+
model: "Lead",
18+
}),
19+
],
20+
label: "Lead ID",
21+
description: "ID of the lead",
22+
},
23+
},
24+
methods: {
25+
...common.methods,
26+
getMethod() {
27+
return "update";
28+
},
29+
getUpdateId() {
30+
return this.leadId;
31+
},
32+
getSummary() {
33+
return `Lead with ID ${this.leadId} updated successfully`;
34+
},
35+
},
36+
};

components/_1crm/common/constants.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const LIMIT = 100;

components/_1crm/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/_1crm",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream 1CRM Components",
55
"main": "_1crm.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)