Skip to content

Commit cd3d560

Browse files
luancazarinemalexanderlim
authored andcommitted
New Components - everhour (#14307)
* everhour init * init * pnpm update * [Components] everhour #13219 Sources - New Client (Instant) - New Task (Instant) - New Task Time Updated (Instant) Actions - Create Task - Start Timer - Stop Timer * [Components] everhour #13219 Sources - New Client (Instant) - New Task (Instant) - New Task Time Updated (Instant) Actions - Create Task - Start Timer - Stop Timer * fix status options
1 parent d7b33bc commit cd3d560

File tree

15 files changed

+644
-4
lines changed

15 files changed

+644
-4
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { STATUS_OPTIONS } from "../../common/constants.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import everhour from "../../everhour.app.mjs";
4+
5+
export default {
6+
key: "everhour-create-task",
7+
name: "Create Task",
8+
description: "Creates a new task in Everhour. [See the documentation](https://everhour.docs.apiary.io/)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
everhour,
13+
projectId: {
14+
propDefinition: [
15+
everhour,
16+
"projectId",
17+
],
18+
},
19+
name: {
20+
type: "string",
21+
label: "Task Name",
22+
description: "The name of the task to be created.",
23+
},
24+
sectionId: {
25+
propDefinition: [
26+
everhour,
27+
"sectionId",
28+
({ projectId }) => ({
29+
projectId,
30+
}),
31+
],
32+
},
33+
tags: {
34+
propDefinition: [
35+
everhour,
36+
"tags",
37+
],
38+
optional: true,
39+
},
40+
position: {
41+
type: "integer",
42+
label: "Position",
43+
description: "The position of the task",
44+
optional: true,
45+
},
46+
description: {
47+
type: "string",
48+
label: "Description",
49+
description: "A description of the task",
50+
optional: true,
51+
},
52+
dueOn: {
53+
type: "string",
54+
label: "Due Date",
55+
description: "The due date of the task. **Format: YYYY-MM-DD**",
56+
optional: true,
57+
},
58+
status: {
59+
type: "string",
60+
label: "Status",
61+
description: "The status of the task",
62+
options: STATUS_OPTIONS,
63+
optional: true,
64+
},
65+
},
66+
async run({ $ }) {
67+
const response = await this.everhour.createTask({
68+
$,
69+
projectId: this.projectId,
70+
data: {
71+
name: this.name,
72+
section: this.sectionId,
73+
tags: this.tags && parseObject(this.tags),
74+
position: this.position,
75+
description: this.description,
76+
dueOn: this.dueOn,
77+
status: this.status,
78+
},
79+
});
80+
81+
$.export("$summary", `Successfully created task with ID: ${response.id}`);
82+
return response;
83+
},
84+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import everhour from "../../everhour.app.mjs";
2+
3+
export default {
4+
key: "everhour-start-timer",
5+
name: "Start Timer",
6+
description: "Begins a new timer for a task. [See the documentation](https://everhour.docs.apiary.io/#reference/0/timers/start-timer)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
everhour,
11+
projectId: {
12+
propDefinition: [
13+
everhour,
14+
"projectId",
15+
],
16+
},
17+
taskId: {
18+
propDefinition: [
19+
everhour,
20+
"taskId",
21+
({ projectId }) => ({
22+
projectId,
23+
}),
24+
],
25+
},
26+
userDate: {
27+
type: "string",
28+
label: "User Date",
29+
description: "Date string to associate with the timer. Format as 'YYYY-MM-DD'",
30+
optional: true,
31+
},
32+
comment: {
33+
type: "string",
34+
label: "Comment",
35+
description: "An optional comment to associate with the timer",
36+
optional: true,
37+
},
38+
},
39+
async run({ $ }) {
40+
const response = await this.everhour.startTimer({
41+
$,
42+
data: {
43+
task: this.taskId,
44+
userDate: this.userDate,
45+
comment: this.comment,
46+
},
47+
});
48+
49+
$.export("$summary", `Successfully started a timer for task ID: ${this.taskId}`);
50+
return response;
51+
},
52+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import everhour from "../../everhour.app.mjs";
2+
3+
export default {
4+
key: "everhour-stop-timer",
5+
name: "Stop Timer",
6+
description: "Halts the current running timer. [See the documentation](https://everhour.docs.apiary.io/#reference/timers/stop-timer)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
everhour,
11+
},
12+
async run({ $ }) {
13+
const response = await this.everhour.stopTimer();
14+
$.export("$summary", "Successfully stopped the timer");
15+
return response;
16+
},
17+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const LIMIT = 100;
2+
3+
export const STATUS_OPTIONS = [
4+
{
5+
label: "Open",
6+
value: "open",
7+
},
8+
{
9+
label: "Closed",
10+
value: "closed",
11+
},
12+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
Lines changed: 169 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,176 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "everhour",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
projectId: {
9+
type: "string",
10+
label: "Project ID",
11+
description: "The ID of the project",
12+
async options({ page }) {
13+
const projects = await this.listProjects({
14+
params: {
15+
limit: LIMIT,
16+
page: page + 1,
17+
},
18+
});
19+
20+
return projects.map(({
21+
name: label, id: value,
22+
}) => ({
23+
label,
24+
value,
25+
}));
26+
},
27+
},
28+
sectionId: {
29+
type: "string",
30+
label: "Section ID",
31+
description: "The section id of the task",
32+
async options({ projectId }) {
33+
const sections = await this.listSections({
34+
projectId,
35+
});
36+
37+
return sections.map(({
38+
name: label, id: value,
39+
}) => ({
40+
label,
41+
value,
42+
}));
43+
},
44+
},
45+
tags: {
46+
type: "string[]",
47+
label: "Tag IDs",
48+
description: "The tag ids of the task",
49+
async options() {
50+
const tags = await this.listTags();
51+
52+
return tags.map(({
53+
name: label, id: value,
54+
}) => ({
55+
label,
56+
value,
57+
}));
58+
},
59+
},
60+
labels: {
61+
type: "string[]",
62+
label: "Tags",
63+
description: "An array of tags associated with the task",
64+
async options({ projectId }) {
65+
const sections = await this.listSections({
66+
projectId,
67+
});
68+
69+
return sections.map(({
70+
name: label, id: value,
71+
}) => ({
72+
label,
73+
value,
74+
}));
75+
},
76+
},
77+
taskId: {
78+
type: "string",
79+
label: "Task ID",
80+
description: "The ID of the task",
81+
async options({ projectId }) {
82+
const tasks = await this.getProjectTasks({
83+
projectId,
84+
});
85+
return tasks.map(({
86+
name: label, id: value,
87+
}) => ({
88+
label,
89+
value,
90+
}));
91+
},
92+
},
93+
},
594
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
95+
_baseUrl() {
96+
return "https://api.everhour.com";
97+
},
98+
_headers() {
99+
return {
100+
"X-Api-Key": `${this.$auth.api_token}`,
101+
};
102+
},
103+
_makeRequest({
104+
$ = this, path, ...opts
105+
}) {
106+
return axios($, {
107+
url: this._baseUrl() + path,
108+
headers: this._headers(),
109+
...opts,
110+
});
111+
},
112+
listProjects(opts = {}) {
113+
return this._makeRequest({
114+
path: "/projects",
115+
...opts,
116+
});
117+
},
118+
listSections({
119+
projectId, opts,
120+
}) {
121+
return this._makeRequest({
122+
path: `/projects/${projectId}/sections`,
123+
...opts,
124+
});
125+
},
126+
listTags() {
127+
return this._makeRequest({
128+
path: "/tags",
129+
});
130+
},
131+
getProjectTasks({
132+
projectId, ...opts
133+
}) {
134+
return this._makeRequest({
135+
path: `/projects/${projectId}/tasks`,
136+
...opts,
137+
});
138+
},
139+
createTask({
140+
projectId, ...opts
141+
}) {
142+
return this._makeRequest({
143+
method: "POST",
144+
path: `/projects/${projectId}/tasks`,
145+
...opts,
146+
});
147+
},
148+
startTimer(opts = {}) {
149+
return this._makeRequest({
150+
method: "POST",
151+
path: "/timers",
152+
...opts,
153+
});
154+
},
155+
stopTimer(opts = {}) {
156+
return this._makeRequest({
157+
method: "DELETE",
158+
path: "/timers/current",
159+
...opts,
160+
});
161+
},
162+
createWebhook(opts = {}) {
163+
return this._makeRequest({
164+
method: "POST",
165+
path: "/hooks",
166+
...opts,
167+
});
168+
},
169+
deleteWebhook(webhookId) {
170+
return this._makeRequest({
171+
method: "DELETE",
172+
path: `/hooks/${webhookId}`,
173+
});
9174
},
10175
},
11176
};

components/everhour/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/everhour",
3+
"version": "0.1.0",
4+
"description": "Pipedream Everhour Components",
5+
"main": "everhour.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"everhour"
9+
],
10+
"homepage": "https://pipedream.com/apps/everhour",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)