Skip to content

Commit d4150b2

Browse files
committed
add: sendgrid, sftp
1 parent ed11cce commit d4150b2

File tree

7 files changed

+50
-62
lines changed

7 files changed

+50
-62
lines changed

components/sendgrid/actions/send-email-multiple-recipients/send-email-multiple-recipients.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ConfigurationError } from "@pipedream/platform";
2-
import fs from "fs";
1+
import {
2+
ConfigurationError, getFileStream,
3+
} from "@pipedream/platform";
34
import mime from "mime";
45
import validate from "validate.js";
56
import common from "../common/common.mjs";
@@ -9,7 +10,7 @@ export default {
910
key: "sendgrid-send-email-multiple-recipients",
1011
name: "Send Email Multiple Recipients",
1112
description: "This action sends a personalized e-mail to multiple specified recipients. [See the docs here](https://docs.sendgrid.com/api-reference/mail-send/mail-send)",
12-
version: "0.0.6",
13+
version: "0.1.0",
1314
type: "action",
1415
props: {
1516
...common.props,
@@ -156,8 +157,8 @@ export default {
156157
};
157158
props[`attachmentsPath${i}`] = {
158159
type: "string",
159-
label: `Attachment File Path ${i}`,
160-
description: "The path to your file in /tmp dir. [See the documentation](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp) for how to work with tmp dir.",
160+
label: `Attachment File Path or URL ${i}`,
161+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`).",
161162
optional: true,
162163
};
163164
}
@@ -208,10 +209,13 @@ export default {
208209
}
209210
const attachments = [];
210211
for (let i = 1; i <= this.numberOfAttachments; i++) {
211-
const filepath = this.checkTmp(this["attachmentsPath" + i]);
212-
const content = fs.readFileSync(filepath, {
213-
encoding: "base64",
214-
});
212+
const filepath = this["attachmentsPath" + i];
213+
const stream = await getFileStream(filepath);
214+
const chunks = [];
215+
for await (const chunk of stream) {
216+
chunks.push(chunk);
217+
}
218+
const content = Buffer.concat(chunks).toString("base64");
215219
const type = mime.getType(filepath);
216220
attachments.push({
217221
content,

components/sendgrid/actions/send-email-single-recipient/send-email-single-recipient.mjs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from "fs";
1+
import { getFileStream } from "@pipedream/platform";
22
import mime from "mime";
33
import validate from "validate.js";
44
import common from "../common/common.mjs";
@@ -8,7 +8,7 @@ export default {
88
key: "sendgrid-send-email-single-recipient",
99
name: "Send Email Single Recipient",
1010
description: "This action sends a personalized e-mail to the specified recipient. [See the docs here](https://docs.sendgrid.com/api-reference/mail-send/mail-send)",
11-
version: "0.0.8",
11+
version: "0.1.0",
1212
type: "action",
1313
props: {
1414
...common.props,
@@ -178,8 +178,8 @@ export default {
178178
};
179179
props[`attachmentsPath${i}`] = {
180180
type: "string",
181-
label: `Attachment File Path ${i}`,
182-
description: "The path to your file in /tmp dir. [See the documentation](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp) for how to work with tmp dir.",
181+
label: `Attachment File Path or URL ${i}`,
182+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`).",
183183
optional: true,
184184
};
185185
}
@@ -227,10 +227,13 @@ export default {
227227
}
228228
const attachments = [];
229229
for (let i = 1; i <= this.numberOfAttachments; i++) {
230-
const filepath = this.checkTmp(this["attachmentsPath" + i]);
231-
const content = fs.readFileSync(filepath, {
232-
encoding: "base64",
233-
});
230+
const filepath = this["attachmentsPath" + i];
231+
const stream = await getFileStream(filepath);
232+
const chunks = [];
233+
for await (const chunk of stream) {
234+
chunks.push(chunk);
235+
}
236+
const content = Buffer.concat(chunks).toString("base64");
234237
const type = mime.getType(filepath);
235238
attachments.push({
236239
content,

components/sendgrid/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sendgrid",
3-
"version": "0.4.2",
3+
"version": "0.5.0",
44
"description": "Pipedream Sendgrid Components",
55
"main": "sendgrid.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/sendgrid",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^3.0.3",
13+
"@pipedream/platform": "^3.1.0",
1414
"@sendgrid/client": "^7.6.2",
1515
"@sendgrid/eventwebhook": "^7.4.5",
1616
"async-retry": "^1.3.1",

components/sftp/actions/upload-file/upload-file.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import app from "../../sftp.app.mjs";
2-
import fs from "fs";
3-
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
ConfigurationError, getFileStream,
4+
} from "@pipedream/platform";
45

56
export default {
67
key: "sftp-upload-file",
78
name: "Upload File",
89
description: "Uploads a file or string in UTF-8 format to the SFTP server. [See the documentation](https://github.com/theophilusx/ssh2-sftp-client#org99d1b64)",
9-
version: "0.3.0",
10+
version: "0.4.0",
1011
type: "action",
1112
props: {
1213
app,
@@ -30,11 +31,11 @@ export default {
3031
},
3132
async run({ $ }) {
3233
if (!this.data && !this.file) {
33-
throw new ConfigurationError("Either `Data` or `File` must be provided.");
34+
throw new ConfigurationError("Either `Data` or `File Path or URL` must be provided.");
3435
}
3536

3637
const buffer = this.file ?
37-
fs.readFileSync(this.file) :
38+
(await getFileStream(this.file)) :
3839
Buffer.from(this.data);
3940

4041
const response = await this.app.put({

components/sftp/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sftp",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"description": "Pipedream SFTP Components",
55
"main": "sftp.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/sftp",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^3.0.3",
13+
"@pipedream/platform": "^3.1.0",
1414
"ssh2-sftp-client": "^11.0.0"
1515
},
1616
"gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",

components/sftp/sftp.app.mjs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import Client from "ssh2-sftp-client";
2-
import fs from "fs";
32

43
export default {
54
type: "app",
65
app: "sftp",
76
propDefinitions: {
87
file: {
98
type: "string",
10-
label: "File",
11-
description: "Local file on `/tmp` folder to upload to the remote server.",
9+
label: "File Path or URL",
10+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`).",
1211
optional: true,
13-
options() {
14-
return fs.readdirSync("/tmp", {
15-
withFileTypes: true,
16-
})
17-
.filter((file) => !file.isDirectory())
18-
.map((file) => file.name);
19-
},
2012
},
2113
},
2214
methods: {

pnpm-lock.yaml

Lines changed: 14 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)