Skip to content

Commit a05ef4d

Browse files
Merge branch 'master' into openai-chat-updates
2 parents 82c914d + 0a027c5 commit a05ef4d

File tree

11 files changed

+578
-6
lines changed

11 files changed

+578
-6
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import charthop from "../../charthop.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "charthop-create-employee",
6+
name: "Create Employee",
7+
description: "Adds a new employee to the system. [See the documentation](https://api.charthop.com/swagger#/person/createPerson)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
charthop,
12+
orgId: {
13+
propDefinition: [
14+
charthop,
15+
"orgId",
16+
],
17+
},
18+
name: {
19+
type: "string",
20+
label: "Name",
21+
description: "Name of the employee",
22+
},
23+
additionalProperties: {
24+
type: "object",
25+
label: "Additional Properties",
26+
description: "Additional properties to add to the employee",
27+
optional: true,
28+
},
29+
},
30+
async run({ $ }) {
31+
const additionalProperties = this.additionalProperties
32+
? parseObject(this.additionalProperties)
33+
: {};
34+
35+
const response = await this.charthop.createPerson({
36+
$,
37+
orgId: this.orgId,
38+
data: {
39+
name: this.name,
40+
...additionalProperties,
41+
},
42+
});
43+
44+
$.export("$summary", `Successfully created employee with ID: ${response.id}`);
45+
return response;
46+
},
47+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import charthop from "../../charthop.app.mjs";
2+
3+
export default {
4+
key: "charthop-search-organization",
5+
name: "Search Organization",
6+
description: "Return people, job, group, and field data for a particular org that match a provided search string. [See the documentation](https://api.charthop.com/swagger#/search/searchOrgData)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
charthop,
11+
orgId: {
12+
propDefinition: [
13+
charthop,
14+
"orgId",
15+
],
16+
},
17+
q: {
18+
type: "string",
19+
label: "Query",
20+
description: "The search query",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.charthop.searchOrganization({
25+
$,
26+
orgId: this.orgId,
27+
params: {
28+
q: this.q,
29+
includeFormer: true,
30+
},
31+
});
32+
33+
$.export("$summary", "Successfully completed search query");
34+
return response;
35+
},
36+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import charthop from "../../charthop.app.mjs";
2+
3+
export default {
4+
key: "charthop-update-employee-details",
5+
name: "Update Employee Details",
6+
description: "Updates an existing employee's details. [See the documentation](https://api.charthop.com/swagger#/user/updateUser)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
charthop,
11+
orgId: {
12+
propDefinition: [
13+
charthop,
14+
"orgId",
15+
],
16+
},
17+
employeeId: {
18+
propDefinition: [
19+
charthop,
20+
"employeeId",
21+
(c) => ({
22+
orgId: c.orgId,
23+
}),
24+
],
25+
reloadProps: true,
26+
},
27+
},
28+
async additionalProps() {
29+
const props = {};
30+
if (!this.employeeId || !this.orgId) {
31+
return props;
32+
}
33+
34+
const employee = await this.charthop.getPerson({
35+
orgId: this.orgId,
36+
personId: this.employeeId,
37+
});
38+
39+
for (const [
40+
key,
41+
value,
42+
] of Object.entries(employee)) {
43+
if (key === "id") {
44+
continue;
45+
}
46+
props[key] = {
47+
type: "string",
48+
label: `${key}`,
49+
default: key === "name"
50+
? (`${value?.first} ${value?.last}`).trim()
51+
: `${value}`,
52+
};
53+
}
54+
55+
return props;
56+
},
57+
async run({ $ }) {
58+
const {
59+
charthop,
60+
orgId,
61+
employeeId,
62+
...fields
63+
} = this;
64+
65+
await charthop.updatePerson({
66+
$,
67+
orgId,
68+
personId: employeeId,
69+
data: {
70+
...fields,
71+
},
72+
});
73+
74+
const response = await charthop.getPerson({
75+
$,
76+
orgId,
77+
personId: employeeId,
78+
});
79+
80+
$.export("$summary", `Successfully updated employee with ID ${employeeId}`);
81+
return response;
82+
},
83+
};
Lines changed: 207 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,214 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "charthop",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
orgId: {
8+
type: "string",
9+
label: "Organization ID",
10+
description: "The identifier of an organization",
11+
async options({ prevContext }) {
12+
const params = prevContext?.from
13+
? {
14+
from: prevContext.from,
15+
}
16+
: {};
17+
const { data } = await this.listOrgs({
18+
params,
19+
});
20+
const options = data?.map(({
21+
id: value, name: label,
22+
}) => ({
23+
value,
24+
label,
25+
})) || [];
26+
return {
27+
options,
28+
context: {
29+
from: options[options.length - 1].id,
30+
},
31+
};
32+
},
33+
},
34+
employeeId: {
35+
type: "string",
36+
label: "Employee ID",
37+
description: "The identifier of an employee",
38+
async options({
39+
orgId, prevContext,
40+
}) {
41+
const params = {
42+
includeAll: true,
43+
};
44+
if (prevContext?.from) {
45+
params.from = prevContext.from;
46+
}
47+
const { data } = await this.listPersons({
48+
orgId,
49+
params: {
50+
...params,
51+
},
52+
});
53+
const options = data?.map(({
54+
id: value, name,
55+
}) => ({
56+
value,
57+
label: (`${name?.first} ${name?.last}`).trim(),
58+
})) || [];
59+
return {
60+
options,
61+
context: {
62+
from: data[data.length - 1].id,
63+
},
64+
};
65+
},
66+
},
67+
groupTypeId: {
68+
type: "string",
69+
label: "Group Type ID",
70+
description: "The identifier of a group type",
71+
async options({
72+
orgId, prevContext,
73+
}) {
74+
const params = {
75+
includeAll: true,
76+
};
77+
if (prevContext?.from) {
78+
params.from = prevContext.from;
79+
}
80+
const { data } = await this.listGroupTypes({
81+
orgId,
82+
params: {
83+
...params,
84+
},
85+
});
86+
const options = data?.map(({
87+
id: value, name: label,
88+
}) => ({
89+
value,
90+
label,
91+
})) || [];
92+
return {
93+
options,
94+
context: {
95+
from: data[data.length - 1].id,
96+
},
97+
};
98+
},
99+
},
100+
},
5101
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
102+
_baseUrl() {
103+
return "https://api.charthop.com";
104+
},
105+
_makeRequest({
106+
$ = this,
107+
path,
108+
...otherOpts
109+
}) {
110+
return axios($, {
111+
...otherOpts,
112+
url: `${this._baseUrl()}${path}`,
113+
headers: {
114+
"Authorization": `Bearer ${this.$auth.api_token}`,
115+
"Content-Type": "application/json",
116+
},
117+
});
118+
},
119+
listOrgs(opts = {}) {
120+
return this._makeRequest({
121+
path: "/v1/org",
122+
...opts,
123+
});
124+
},
125+
listPersons({
126+
orgId, ...opts
127+
}) {
128+
return this._makeRequest({
129+
path: `/v2/org/${orgId}/person`,
130+
...opts,
131+
});
132+
},
133+
listJobs({
134+
orgId, ...opts
135+
}) {
136+
return this._makeRequest({
137+
path: `/v2/org/${orgId}/job`,
138+
...opts,
139+
});
140+
},
141+
listGroupTypes({
142+
orgId, ...opts
143+
}) {
144+
return this._makeRequest({
145+
path: `/v1/org/${orgId}/group-type`,
146+
...opts,
147+
});
148+
},
149+
listGroups({
150+
orgId, type, ...opts
151+
}) {
152+
return this._makeRequest({
153+
path: `/v2/org/${orgId}/group/${type}`,
154+
...opts,
155+
});
156+
},
157+
getPerson({
158+
orgId, personId, ...opts
159+
}) {
160+
return this._makeRequest({
161+
path: `/v2/org/${orgId}/person/${personId}`,
162+
...opts,
163+
});
164+
},
165+
createPerson({
166+
orgId, ...opts
167+
}) {
168+
return this._makeRequest({
169+
method: "POST",
170+
path: `/v2/org/${orgId}/person`,
171+
...opts,
172+
});
173+
},
174+
updatePerson({
175+
orgId, personId, ...opts
176+
}) {
177+
return this._makeRequest({
178+
method: "PATCH",
179+
path: `/v2/org/${orgId}/person/${personId}`,
180+
...opts,
181+
});
182+
},
183+
searchOrganization({
184+
orgId, ...opts
185+
}) {
186+
return this._makeRequest({
187+
path: `/v1/org/${orgId}/search`,
188+
...opts,
189+
});
190+
},
191+
async *paginate({
192+
resourceFn,
193+
args,
194+
max,
195+
}) {
196+
let count = 0;
197+
do {
198+
const {
199+
data, next,
200+
} = await resourceFn(args);
201+
for (const item of data) {
202+
yield item;
203+
if (max && ++count >= max) {
204+
return;
205+
}
206+
args.params = {
207+
...args.params,
208+
from: next,
209+
};
210+
}
211+
} while (args.params?.from);
9212
},
10213
},
11214
};

0 commit comments

Comments
 (0)