|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | app: "domo", |
4 | | - propDefinitions: {}, |
| 6 | + version: "0.0.{{ts}}", |
| 7 | + propDefinitions: { |
| 8 | + // Emit new event when a new dataset is added |
| 9 | + datasetOwner: { |
| 10 | + type: "string", |
| 11 | + label: "Dataset Owner", |
| 12 | + description: "Filter datasets by owner.", |
| 13 | + optional: true, |
| 14 | + }, |
| 15 | + datasetTags: { |
| 16 | + type: "string[]", |
| 17 | + label: "Dataset Tags", |
| 18 | + description: "Filter datasets by tags.", |
| 19 | + optional: true, |
| 20 | + }, |
| 21 | + // Emit new event when data within a specific card is updated |
| 22 | + cardId: { |
| 23 | + type: "string", |
| 24 | + label: "Card ID", |
| 25 | + description: "The ID of the card to monitor for data updates.", |
| 26 | + }, |
| 27 | + thresholds: { |
| 28 | + type: "string[]", |
| 29 | + label: "Thresholds", |
| 30 | + description: "Conditions or thresholds for data updates, in JSON format.", |
| 31 | + optional: true, |
| 32 | + }, |
| 33 | + conditions: { |
| 34 | + type: "string[]", |
| 35 | + label: "Conditions", |
| 36 | + description: "Conditions for data updates, in JSON format.", |
| 37 | + optional: true, |
| 38 | + }, |
| 39 | + projectId: { |
| 40 | + type: "string", |
| 41 | + label: "Project ID", |
| 42 | + description: "The ID of the project.", |
| 43 | + optional: true, |
| 44 | + async options() { |
| 45 | + const projects = await this.listProjects(); |
| 46 | + return projects.map((project) => ({ |
| 47 | + label: project.name, |
| 48 | + value: project.id, |
| 49 | + })); |
| 50 | + }, |
| 51 | + }, |
| 52 | + listId: { |
| 53 | + type: "string", |
| 54 | + label: "List ID", |
| 55 | + description: "The ID of the list.", |
| 56 | + optional: true, |
| 57 | + async options() { |
| 58 | + if (!this.projectId) { |
| 59 | + return []; |
| 60 | + } |
| 61 | + const lists = await this.listLists({ |
| 62 | + projectId: this.projectId, |
| 63 | + }); |
| 64 | + return lists.map((list) => ({ |
| 65 | + label: list.name, |
| 66 | + value: list.id, |
| 67 | + })); |
| 68 | + }, |
| 69 | + }, |
| 70 | + // Emit new event when an alert is triggered |
| 71 | + alertTypes: { |
| 72 | + type: "string[]", |
| 73 | + label: "Alert Types", |
| 74 | + description: "Filter alerts by specific types.", |
| 75 | + optional: true, |
| 76 | + }, |
| 77 | + relatedDatasets: { |
| 78 | + type: "string[]", |
| 79 | + label: "Related Datasets", |
| 80 | + description: "Filter alerts by related datasets.", |
| 81 | + optional: true, |
| 82 | + }, |
| 83 | + // Add new rows of data to an existing dataset |
| 84 | + datasetId: { |
| 85 | + type: "string", |
| 86 | + label: "Dataset ID", |
| 87 | + description: "The ID of the dataset to add data to.", |
| 88 | + }, |
| 89 | + data: { |
| 90 | + type: "string[]", |
| 91 | + label: "Data", |
| 92 | + description: |
| 93 | + "The data to add to the dataset, as JSON strings representing objects or arrays.", |
| 94 | + }, |
| 95 | + // Update the description of an existing card |
| 96 | + updateCardId: { |
| 97 | + type: "string", |
| 98 | + label: "Card ID", |
| 99 | + description: "The ID of the card to update.", |
| 100 | + }, |
| 101 | + newDescription: { |
| 102 | + type: "string", |
| 103 | + label: "New Description", |
| 104 | + description: "The new description for the card.", |
| 105 | + }, |
| 106 | + }, |
5 | 107 | methods: { |
6 | | - // this.$auth contains connected account data |
| 108 | + // Existing method |
7 | 109 | authKeys() { |
8 | 110 | console.log(Object.keys(this.$auth)); |
9 | 111 | }, |
| 112 | + _baseUrl() { |
| 113 | + return "https://api.domo.com"; |
| 114 | + }, |
| 115 | + async _makeRequest(opts = {}) { |
| 116 | + const { |
| 117 | + $, method = "GET", path = "/", headers = {}, data, params, ...otherOpts |
| 118 | + } = opts; |
| 119 | + return axios($, { |
| 120 | + method, |
| 121 | + url: this._baseUrl() + path, |
| 122 | + headers: { |
| 123 | + ...headers, |
| 124 | + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, |
| 125 | + "Content-Type": "application/json", |
| 126 | + }, |
| 127 | + data: data || undefined, |
| 128 | + params: params || undefined, |
| 129 | + ...otherOpts, |
| 130 | + }); |
| 131 | + }, |
| 132 | + // Method to list all projects |
| 133 | + async listProjects(opts = {}) { |
| 134 | + return this._makeRequest({ |
| 135 | + method: "GET", |
| 136 | + path: "/v1/projects", |
| 137 | + ...opts, |
| 138 | + }); |
| 139 | + }, |
| 140 | + // Method to list all lists within a project |
| 141 | + async listLists({ |
| 142 | + projectId, ...opts |
| 143 | + }) { |
| 144 | + return this._makeRequest({ |
| 145 | + method: "GET", |
| 146 | + path: `/v1/projects/${projectId}/lists`, |
| 147 | + ...opts, |
| 148 | + }); |
| 149 | + }, |
| 150 | + // Method to add new rows to a dataset |
| 151 | + async addDatasetRows({ |
| 152 | + datasetId, data, ...opts |
| 153 | + }) { |
| 154 | + const parsedData = data.map((row) => JSON.parse(row)); |
| 155 | + return this._makeRequest({ |
| 156 | + method: "POST", |
| 157 | + path: `/v1/datasets/${datasetId}/data`, |
| 158 | + data: parsedData, |
| 159 | + ...opts, |
| 160 | + }); |
| 161 | + }, |
| 162 | + // Method to update card description |
| 163 | + async updateCardDescription({ |
| 164 | + cardId, newDescription, ...opts |
| 165 | + }) { |
| 166 | + return this._makeRequest({ |
| 167 | + method: "PUT", |
| 168 | + path: `/v1/cards/${cardId}`, |
| 169 | + data: { |
| 170 | + description: newDescription, |
| 171 | + }, |
| 172 | + ...opts, |
| 173 | + }); |
| 174 | + }, |
| 175 | + // Method to list alerts |
| 176 | + async listAlerts(opts = {}) { |
| 177 | + return this._makeRequest({ |
| 178 | + method: "GET", |
| 179 | + path: "/v1/alerts", |
| 180 | + ...opts, |
| 181 | + }); |
| 182 | + }, |
| 183 | + // Method to get alert details |
| 184 | + async getAlertDetails({ |
| 185 | + alertId, ...opts |
| 186 | + }) { |
| 187 | + return this._makeRequest({ |
| 188 | + method: "GET", |
| 189 | + path: `/v1/alerts/${alertId}`, |
| 190 | + ...opts, |
| 191 | + }); |
| 192 | + }, |
| 193 | + // Method to get card data |
| 194 | + async getCardData({ |
| 195 | + cardId, ...opts |
| 196 | + }) { |
| 197 | + return this._makeRequest({ |
| 198 | + method: "GET", |
| 199 | + path: `/v1/cards/${cardId}/data`, |
| 200 | + ...opts, |
| 201 | + }); |
| 202 | + }, |
| 203 | + // Pagination method |
| 204 | + async paginate(fn, ...opts) { |
| 205 | + let results = []; |
| 206 | + let response; |
| 207 | + let offset = 0; |
| 208 | + const limit = 100; |
| 209 | + |
| 210 | + do { |
| 211 | + response = await fn({ |
| 212 | + offset, |
| 213 | + limit, |
| 214 | + ...opts, |
| 215 | + }); |
| 216 | + results = results.concat(response); |
| 217 | + offset += limit; |
| 218 | + } while (response.length === limit); |
| 219 | + |
| 220 | + return results; |
| 221 | + }, |
10 | 222 | }, |
11 | 223 | }; |
0 commit comments