|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | +import { LIMIT } from "./common/constants.mjs"; |
| 3 | + |
1 | 4 | export default { |
2 | 5 | type: "app", |
3 | 6 | 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 | + }, |
5 | 94 | 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 | + }); |
9 | 174 | }, |
10 | 175 | }, |
11 | 176 | }; |
0 commit comments