Skip to content

Commit 14956af

Browse files
authored
New Components - copper (#14294)
* init * new components * pnpm-lock.yaml * fix typo
1 parent 52f29a4 commit 14956af

File tree

14 files changed

+710
-58
lines changed

14 files changed

+710
-58
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import copper from "../../copper.app.mjs";
2+
3+
export default {
4+
key: "copper-associate-to-project",
5+
name: "Associate to Project",
6+
description: "Relates an existing project with an existing CRM object. [See the documentation](https://developer.copper.com/related-items/relate-an-existing-record-to-an-entity.html)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
copper,
11+
projectId: {
12+
propDefinition: [
13+
copper,
14+
"objectId",
15+
() => ({
16+
objectType: "projects",
17+
}),
18+
],
19+
label: "Project ID",
20+
description: "The ID of the project you wish to relate",
21+
},
22+
objectType: {
23+
propDefinition: [
24+
copper,
25+
"objectType",
26+
],
27+
},
28+
objectId: {
29+
propDefinition: [
30+
copper,
31+
"objectId",
32+
(c) => ({
33+
objectType: c.objectType,
34+
}),
35+
],
36+
},
37+
},
38+
async run({ $ }) {
39+
const response = await this.copper.relateProjectToCrmObject({
40+
$,
41+
objectType: this.objectType,
42+
objectId: this.objectId,
43+
data: {
44+
resource: {
45+
id: this.projectId,
46+
type: "project",
47+
},
48+
},
49+
});
50+
$.export("$summary", `Successfully associated Project ID ${this.projectId} with CRM ID ${this.objectId}`);
51+
return response;
52+
},
53+
};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import copper from "../../copper.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "copper-create-update-person",
6+
name: "Create or Update Person",
7+
description: "Creates a new person or updates an existing one based on email address. [See the documentation](https://developer.copper.com/people/create-a-new-person.html)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
copper,
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "Email address of the person. If email already exists, the person will be updated",
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Name of the contact. Required if creating a new person.",
21+
optional: true,
22+
},
23+
streetAddress: {
24+
type: "string",
25+
label: "Street Address",
26+
description: "Street address of the person",
27+
optional: true,
28+
},
29+
city: {
30+
type: "string",
31+
label: "City",
32+
description: "City address of the person",
33+
optional: true,
34+
},
35+
state: {
36+
type: "string",
37+
label: "State",
38+
description: "State address of the person",
39+
optional: true,
40+
},
41+
postalCode: {
42+
type: "string",
43+
label: "Postal Code",
44+
description: "Postal code of the person",
45+
optional: true,
46+
},
47+
country: {
48+
type: "string",
49+
label: "Country",
50+
description: "Country of the person",
51+
optional: true,
52+
},
53+
phone: {
54+
type: "string",
55+
label: "Phone",
56+
description: "Phone number of the person",
57+
optional: true,
58+
},
59+
},
60+
async run({ $ }) {
61+
let response;
62+
const hasAddress = this.streetAddress
63+
|| this.city
64+
|| this.state
65+
|| this.postalCode
66+
|| this.country;
67+
const data = {
68+
emails: [
69+
{
70+
email: this.email,
71+
category: "work",
72+
},
73+
],
74+
name: this.name,
75+
address: hasAddress && {
76+
street: this.streetAddress,
77+
city: this.city,
78+
state: this.state,
79+
postal_code: this.postalCode,
80+
country: this.country,
81+
},
82+
phone_numbers: this.phone && [
83+
{
84+
number: this.phone,
85+
category: "work",
86+
},
87+
],
88+
};
89+
90+
// search for the person
91+
const person = await this.copper.listObjects({
92+
$,
93+
objectType: "people",
94+
data: {
95+
emails: [
96+
this.email,
97+
],
98+
},
99+
});
100+
101+
if (!person?.length && !this.name) {
102+
throw new ConfigurationError(`Person with email ${this.email} not found. Name is required for creating a new person.`);
103+
}
104+
105+
// create person if not found
106+
if (!person?.length) {
107+
response = await this.copper.createPerson({
108+
$,
109+
data,
110+
});
111+
}
112+
// update person if found
113+
else {
114+
response = await this.copper.updatePerson({
115+
$,
116+
personId: person[0].id,
117+
data,
118+
});
119+
}
120+
121+
$.export("$summary", `Successfully ${person?.length
122+
? "updated"
123+
: "created"} person with ID: ${response.id}`);
124+
return response;
125+
},
126+
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import copper from "../../copper.app.mjs";
2+
3+
export default {
4+
key: "copper-create-update-project",
5+
name: "Create or Update Project",
6+
description: "Creates a new project or updates an existing one based on the project name. [See the documentation](https://developer.copper.com/projects/create-a-new-project.html)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
copper,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name of the project. If a project with the specified name already exists, it will be updated",
15+
},
16+
details: {
17+
type: "string",
18+
label: "Details",
19+
description: "Description of the Project",
20+
optional: true,
21+
},
22+
assigneeId: {
23+
propDefinition: [
24+
copper,
25+
"objectId",
26+
() => ({
27+
objectType: "users",
28+
}),
29+
],
30+
label: "Assignee ID",
31+
description: "The ID of the User that will be the owner of the Project",
32+
optional: true,
33+
},
34+
status: {
35+
propDefinition: [
36+
copper,
37+
"status",
38+
],
39+
},
40+
tags: {
41+
propDefinition: [
42+
copper,
43+
"tags",
44+
],
45+
},
46+
},
47+
async run({ $ }) {
48+
let response;
49+
const data = {
50+
name: this.name,
51+
assignee_id: this.assigneeId,
52+
status: this.status,
53+
tags: this.tags,
54+
};
55+
56+
// search for the project
57+
const project = await this.copper.listObjects({
58+
$,
59+
objectType: "projects",
60+
data: {
61+
name: this.name,
62+
},
63+
});
64+
65+
// create project if not found
66+
if (!project?.length) {
67+
response = await this.copper.createProject({
68+
$,
69+
data,
70+
});
71+
}
72+
// update project if found
73+
else {
74+
response = await this.copper.updateProject({
75+
$,
76+
projectId: project[0].id,
77+
data,
78+
});
79+
}
80+
81+
$.export("$summary", `Successfully ${project?.length
82+
? "updated"
83+
: "created"} project with ID: ${response.id}`);
84+
return response;
85+
},
86+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import copper from "../../copper.app.mjs";
2+
3+
export default {
4+
key: "copper-get-object",
5+
name: "Get Object",
6+
description: "Retrieves an existing CRM object. [See the documentation](https://developer.copper.com/account-and-users/fetch-user-by-id.html)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
copper,
11+
objectType: {
12+
propDefinition: [
13+
copper,
14+
"objectType",
15+
],
16+
},
17+
objectId: {
18+
propDefinition: [
19+
copper,
20+
"objectId",
21+
(c) => ({
22+
objectType: c.objectType,
23+
}),
24+
],
25+
},
26+
},
27+
async run({ $ }) {
28+
const response = await this.copper.getObject({
29+
objectType: this.objectType,
30+
objectId: this.objectId,
31+
$,
32+
});
33+
$.export("$summary", `Successfully retrieved CRM object with ID ${this.objectId}`);
34+
return response;
35+
},
36+
};

0 commit comments

Comments
 (0)