@pipedream/freshdesk 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ import freshdesk from "../../freshdesk.app.mjs";
2
+ import { axios } from "@pipedream/platform";
3
+ import fs from "fs";
4
+
5
+ export default {
6
+ key: "freshdesk-download-attachment",
7
+ name: "Download Attachment",
8
+ description: "Download an attachment from a ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)",
9
+ version: "0.0.1",
10
+ type: "action",
11
+ props: {
12
+ freshdesk,
13
+ ticketId: {
14
+ propDefinition: [
15
+ freshdesk,
16
+ "ticketId",
17
+ ],
18
+ },
19
+ attachmentId: {
20
+ type: "integer",
21
+ label: "Attachment ID",
22
+ description: "The ID of the attachment to download",
23
+ async options() {
24
+ const attachments = await this.listTicketAttachments();
25
+ return attachments.map(({
26
+ id, name,
27
+ }) => ({
28
+ value: id,
29
+ label: name,
30
+ }));
31
+ },
32
+ },
33
+ syncDir: {
34
+ type: "dir",
35
+ accessMode: "write",
36
+ sync: true,
37
+ },
38
+ },
39
+ methods: {
40
+ async listTicketAttachments(opts = {}) {
41
+ const { attachments } = await this.freshdesk.getTicket({
42
+ ticketId: this.ticketId,
43
+ ...opts,
44
+ });
45
+ return attachments;
46
+ },
47
+ },
48
+ async run({ $ }) {
49
+ const attachments = await this.listTicketAttachments({
50
+ $,
51
+ });
52
+ const attachment = attachments.find(({ id }) => id === this.attachmentId);
53
+
54
+ const response = await axios($, {
55
+ url: attachment.attachment_url,
56
+ responseType: "arraybuffer",
57
+ });
58
+
59
+ const buffer = Buffer.from(response);
60
+ const downloadedFilepath = `/tmp/${attachment.name}`;
61
+ fs.writeFileSync(downloadedFilepath, buffer);
62
+
63
+ const filedata = [
64
+ attachment.name,
65
+ downloadedFilepath,
66
+ ];
67
+
68
+ return {
69
+ filedata,
70
+ attachment,
71
+ };
72
+ },
73
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/freshdesk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Pipedream Freshdesk Components",
5
5
  "main": "freshdesk.app.mjs",
6
6
  "keywords": [