|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | app: "ninjaone", |
4 | | - propDefinitions: {}, |
| 6 | + propDefinitions: { |
| 7 | + ticketPriority: { |
| 8 | + type: "string", |
| 9 | + label: "Ticket Priority", |
| 10 | + description: "Filter support tickets by priority", |
| 11 | + async options() { |
| 12 | + const priorities = await this.getTicketPriorities(); |
| 13 | + return priorities.map((priority) => ({ |
| 14 | + label: priority.name, |
| 15 | + value: priority.id, |
| 16 | + })); |
| 17 | + }, |
| 18 | + }, |
| 19 | + ticketStatus: { |
| 20 | + type: "string", |
| 21 | + label: "Ticket Status", |
| 22 | + description: "Filter support tickets by status", |
| 23 | + async options() { |
| 24 | + const statuses = await this.getTicketStatuses(); |
| 25 | + return statuses.map((status) => ({ |
| 26 | + label: status.name, |
| 27 | + value: status.id, |
| 28 | + })); |
| 29 | + }, |
| 30 | + }, |
| 31 | + deviceGroup: { |
| 32 | + type: "string", |
| 33 | + label: "Device Group", |
| 34 | + description: "Specify the device group to monitor", |
| 35 | + async options() { |
| 36 | + const groups = await this.getDeviceGroups(); |
| 37 | + return groups.map((group) => ({ |
| 38 | + label: group.name, |
| 39 | + value: group.id, |
| 40 | + })); |
| 41 | + }, |
| 42 | + }, |
| 43 | + deviceType: { |
| 44 | + type: "string", |
| 45 | + label: "Device Type", |
| 46 | + description: "Specify the device type to monitor", |
| 47 | + async options() { |
| 48 | + const types = await this.getDeviceTypes(); |
| 49 | + return types.map((type) => ({ |
| 50 | + label: type.name, |
| 51 | + value: type.id, |
| 52 | + })); |
| 53 | + }, |
| 54 | + }, |
| 55 | + sessionType: { |
| 56 | + type: "string", |
| 57 | + label: "Session Type", |
| 58 | + description: "Filter remote access sessions by type", |
| 59 | + optional: true, |
| 60 | + async options() { |
| 61 | + const types = await this.getSessionTypes(); |
| 62 | + return types.map((type) => ({ |
| 63 | + label: type.name, |
| 64 | + value: type.id, |
| 65 | + })); |
| 66 | + }, |
| 67 | + }, |
| 68 | + technician: { |
| 69 | + type: "string", |
| 70 | + label: "Technician", |
| 71 | + description: "Filter remote access sessions by technician", |
| 72 | + optional: true, |
| 73 | + async options() { |
| 74 | + const technicians = await this.getTechnicians(); |
| 75 | + return technicians.map((tech) => ({ |
| 76 | + label: tech.name, |
| 77 | + value: tech.id, |
| 78 | + })); |
| 79 | + }, |
| 80 | + }, |
| 81 | + title: { |
| 82 | + type: "string", |
| 83 | + label: "Title", |
| 84 | + description: "Title of the support ticket", |
| 85 | + }, |
| 86 | + description: { |
| 87 | + type: "string", |
| 88 | + label: "Description", |
| 89 | + description: "Description of the support ticket", |
| 90 | + }, |
| 91 | + priority: { |
| 92 | + type: "string", |
| 93 | + label: "Priority", |
| 94 | + description: "Priority level of the support ticket", |
| 95 | + }, |
| 96 | + assignedTechnician: { |
| 97 | + type: "string", |
| 98 | + label: "Assigned Technician", |
| 99 | + description: "Technician to assign the ticket to", |
| 100 | + optional: true, |
| 101 | + }, |
| 102 | + dueDate: { |
| 103 | + type: "string", |
| 104 | + label: "Due Date", |
| 105 | + description: "Due date for the support ticket", |
| 106 | + optional: true, |
| 107 | + }, |
| 108 | + deviceId: { |
| 109 | + type: "string", |
| 110 | + label: "Device ID", |
| 111 | + description: "Identifier of the device to update", |
| 112 | + }, |
| 113 | + deviceAttributes: { |
| 114 | + type: "string[]", |
| 115 | + label: "Device Attributes", |
| 116 | + description: "Attributes to update on the device", |
| 117 | + }, |
| 118 | + }, |
5 | 119 | methods: { |
6 | | - // this.$auth contains connected account data |
7 | | - authKeys() { |
8 | | - console.log(Object.keys(this.$auth)); |
| 120 | + _baseUrl() { |
| 121 | + return "https://api.ninjaone.com/v2"; |
| 122 | + }, |
| 123 | + async _makeRequest(opts = {}) { |
| 124 | + const { |
| 125 | + $ = this, method = "GET", path = "/", headers, ...otherOpts |
| 126 | + } = opts; |
| 127 | + return axios($, { |
| 128 | + ...otherOpts, |
| 129 | + method, |
| 130 | + url: this._baseUrl() + path, |
| 131 | + headers: { |
| 132 | + ...headers, |
| 133 | + Authorization: `Bearer ${this.$auth.oauth_access_token}`, |
| 134 | + }, |
| 135 | + }); |
| 136 | + }, |
| 137 | + async getTicketPriorities() { |
| 138 | + return this._makeRequest({ |
| 139 | + path: "/ticketing/ticket-priorities", |
| 140 | + }); |
| 141 | + }, |
| 142 | + async getTicketStatuses() { |
| 143 | + return this._makeRequest({ |
| 144 | + path: "/ticketing/ticket-statuses", |
| 145 | + }); |
| 146 | + }, |
| 147 | + async getDeviceGroups() { |
| 148 | + return this._makeRequest({ |
| 149 | + path: "/device-groups", |
| 150 | + }); |
| 151 | + }, |
| 152 | + async getDeviceTypes() { |
| 153 | + return this._makeRequest({ |
| 154 | + path: "/device-types", |
| 155 | + }); |
| 156 | + }, |
| 157 | + async getSessionTypes() { |
| 158 | + return this._makeRequest({ |
| 159 | + path: "/session-types", |
| 160 | + }); |
| 161 | + }, |
| 162 | + async getTechnicians() { |
| 163 | + return this._makeRequest({ |
| 164 | + path: "/technicians", |
| 165 | + }); |
| 166 | + }, |
| 167 | + async createSupportTicket({ |
| 168 | + title, description, priority, assignedTechnician, dueDate, |
| 169 | + }) { |
| 170 | + return this._makeRequest({ |
| 171 | + method: "POST", |
| 172 | + path: "/ticketing/ticket", |
| 173 | + data: { |
| 174 | + title, |
| 175 | + description, |
| 176 | + priority, |
| 177 | + assignedTechnician, |
| 178 | + dueDate, |
| 179 | + }, |
| 180 | + }); |
| 181 | + }, |
| 182 | + async updateDevice(deviceId, deviceAttributes) { |
| 183 | + return this._makeRequest({ |
| 184 | + method: "PATCH", |
| 185 | + path: `/device/${deviceId}`, |
| 186 | + data: JSON.parse(deviceAttributes), |
| 187 | + }); |
| 188 | + }, |
| 189 | + async emitNewSupportTicket({ |
| 190 | + ticketPriority, ticketStatus, |
| 191 | + }) { |
| 192 | + const response = await this._makeRequest({ |
| 193 | + path: "/ticketing/ticket", |
| 194 | + params: { |
| 195 | + priority: ticketPriority, |
| 196 | + status: ticketStatus, |
| 197 | + }, |
| 198 | + }); |
| 199 | + response.forEach((ticket) => this.$emit(ticket, { |
| 200 | + id: ticket.id, |
| 201 | + summary: `New ticket: ${ticket.title}`, |
| 202 | + ts: new Date().getTime(), |
| 203 | + })); |
| 204 | + }, |
| 205 | + async emitDeviceOnline({ |
| 206 | + deviceGroup, deviceType, |
| 207 | + }) { |
| 208 | + const response = await this._makeRequest({ |
| 209 | + path: "/devices", |
| 210 | + params: { |
| 211 | + group: deviceGroup, |
| 212 | + type: deviceType, |
| 213 | + }, |
| 214 | + }); |
| 215 | + response.forEach((device) => this.$emit(device, { |
| 216 | + id: device.id, |
| 217 | + summary: `Device online: ${device.name}`, |
| 218 | + ts: new Date().getTime(), |
| 219 | + })); |
| 220 | + }, |
| 221 | + async emitRemoteAccessSession({ |
| 222 | + sessionType, technician, |
| 223 | + }) { |
| 224 | + const response = await this._makeRequest({ |
| 225 | + path: "/device/{id}/activities", |
| 226 | + params: { |
| 227 | + sessionType, |
| 228 | + technician, |
| 229 | + }, |
| 230 | + }); |
| 231 | + response.forEach((session) => this.$emit(session, { |
| 232 | + id: session.id, |
| 233 | + summary: `Remote session initiated by ${session.technician}`, |
| 234 | + ts: new Date().getTime(), |
| 235 | + })); |
9 | 236 | }, |
10 | 237 | }, |
| 238 | + version: `0.0.${Date.now()}`, |
11 | 239 | }; |
0 commit comments