Skip to content

Commit 69bbb92

Browse files
committed
add: onlinecheckwriter, pandadoc, pdf4me
1 parent 04ae59a commit 69bbb92

File tree

12 files changed

+54
-104
lines changed

12 files changed

+54
-104
lines changed

components/onlinecheckwriter/actions/mail-pdf-document/mail-pdf-document.mjs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import fs from "fs";
21
import FormData from "form-data";
3-
import { ConfigurationError } from "@pipedream/platform";
2+
import { getFileStream } from "@pipedream/platform";
43
import app from "../../onlinecheckwriter.app.mjs";
54

65
export default {
76
key: "onlinecheckwriter-mail-pdf-document",
87
name: "Mail PDF Document",
98
description: "Mails a PDF document to a destination. [See the documentation](https://apiv3.onlinecheckwriter.com/#878daf05-e36e-44a2-bce8-15f24d72f82e).",
10-
version: "0.0.1",
9+
version: "0.1.0",
1110
type: "action",
1211
props: {
1312
app,
@@ -19,8 +18,8 @@ export default {
1918
},
2019
filePath: {
2120
type: "string",
22-
label: "File Path",
23-
description: "The path to the pdf file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
21+
label: "File Path or URL",
22+
description: "The PDF file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`)",
2423
},
2524
shippingTypeId: {
2625
optional: false,
@@ -167,12 +166,8 @@ export default {
167166
destinationEmail,
168167
} = this;
169168

170-
if (!filePath?.startsWith("/tmp/")) {
171-
throw new ConfigurationError("The file path must start with `/tmp/`.");
172-
}
173-
174169
const data = new FormData();
175-
const file = fs.createReadStream(filePath);
170+
const file = await getFileStream(filePath);
176171
data.append("document_details[file]", file);
177172
data.append("document_details[title]", documentTitle || "");
178173
data.append("shipping[shippingTypeId]", shippingTypeId || "");

components/onlinecheckwriter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/onlinecheckwriter",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream OnlineCheckWriter Components",
55
"main": "onlinecheckwriter.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "3.0.3",
16+
"@pipedream/platform": "^3.1.0",
1717
"form-data": "^4.0.0"
1818
}
1919
}

components/pandadoc/actions/create-document-attachment/create-document-attachment.mjs

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import app from "../../pandadoc.app.mjs";
2-
import { ConfigurationError } from "@pipedream/platform";
3-
import fs from "fs";
4-
import path from "path";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
53
import FormData from "form-data";
64

75
export default {
86
key: "pandadoc-create-document-attachment",
97
name: "Create Document Attachment",
108
description: "Adds an attachment to a document. [See the documentation here](https://developers.pandadoc.com/reference/create-document-attachment)",
119
type: "action",
12-
version: "0.0.7",
10+
version: "0.1.0",
1311
props: {
1412
app,
1513
documentId: {
@@ -31,39 +29,17 @@ export default {
3129
},
3230
},
3331
methods: {
34-
isValidFile(filePath) {
35-
const filePathWithTmp = `/tmp/${filePath}`;
36-
if (fs.existsSync(filePathWithTmp)) {
37-
return filePathWithTmp;
38-
} else if (fs.existsSync(filePath)) {
39-
return filePath;
40-
}
41-
return false;
42-
},
43-
getFileStream(filePath) {
44-
return fs.createReadStream(filePath);
45-
},
46-
getFileMeta(filePath) {
47-
const stats = fs.statSync(filePath);
48-
return {
49-
name: path.basename(filePath),
50-
size: stats.size,
51-
};
52-
},
53-
getFormData(file, fileName) {
54-
const fileValidation = this.isValidFile(file);
55-
if (!fileValidation) {
56-
throw new ConfigurationError("`file` must be a valid file path!");
57-
}
58-
59-
const fileMeta = this.getFileMeta(fileValidation);
60-
const fileContent = this.getFileStream(fileValidation);
32+
async getFormData(file, fileName) {
33+
const {
34+
stream, metadata: {
35+
name, size,
36+
},
37+
} = await getFileStreamAndMetadata(file);
6138
const data = new FormData();
62-
if (fileName) data.append("name", fileName);
63-
data.append("file", fileContent, {
64-
knownLength: fileMeta.size,
39+
data.append("name", fileName || name);
40+
data.append("file", stream, {
41+
knownLength: size,
6542
});
66-
6743
return data;
6844
},
6945
},
@@ -74,7 +50,7 @@ export default {
7450
fileName,
7551
} = this;
7652

77-
const data = this.getFormData(file, fileName);
53+
const data = await this.getFormData(file, fileName);
7854

7955
const response = await this.app.createDocumentAttachments({
8056
$,

components/pandadoc/actions/create-document-from-file/create-document-from-file.mjs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
name: "Create Document From File",
88
description: "Create a document from a file or public file URL. [See the documentation here](https://developers.pandadoc.com/reference/create-document-from-pdf)",
99
type: "action",
10-
version: "0.0.8",
10+
version: "1.0.0",
1111
props: {
1212
app,
1313
name: {
@@ -27,13 +27,6 @@ export default {
2727
app,
2828
"file",
2929
],
30-
optional: true,
31-
},
32-
fileUrl: {
33-
type: "string",
34-
label: "File URL",
35-
description: "A public file URL to use instead of a local file.",
36-
optional: true,
3730
},
3831
documentFolderId: {
3932
propDefinition: [
@@ -55,7 +48,6 @@ export default {
5548
name,
5649
recipients,
5750
file,
58-
fileUrl,
5951
documentFolderId,
6052
} = this;
6153

@@ -66,7 +58,7 @@ export default {
6658
throw new ConfigurationError("**Error parsing recipients** - each must be a valid JSON-stringified object");
6759
}
6860

69-
let data, contentType, json = {
61+
const json = {
7062
name,
7163
recipients: parsedRecipients,
7264
folder_uuid: documentFolderId,
@@ -78,15 +70,9 @@ export default {
7870
: this.fields;
7971
}
8072

81-
if (fileUrl) {
82-
data = json;
83-
contentType = "application/json";
84-
data.url = fileUrl;
85-
} else {
86-
data = this.getFormData(file);
87-
contentType = `multipart/form-data; boundary=${data._boundary}`;
88-
data.append("data", JSON.stringify(json));
89-
}
73+
const data = this.getFormData(file);
74+
const contentType = `multipart/form-data; boundary=${data._boundary}`;
75+
data.append("data", JSON.stringify(json));
9076

9177
const response = await this.app.createDocument({
9278
$,

components/pandadoc/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/pandadoc",
3-
"version": "0.3.0",
3+
"version": "1.0.0",
44
"description": "Pipedream PandaDoc Components",
55
"main": "pandadoc.app.mjs",
66
"keywords": [
@@ -14,7 +14,7 @@
1414
"access": "public"
1515
},
1616
"dependencies": {
17-
"@pipedream/platform": "^1.6.0",
17+
"@pipedream/platform": "^3.1.0",
1818
"form-data": "^4.0.0"
1919
}
2020
}

components/pandadoc/pandadoc.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export default {
8888
},
8989
file: {
9090
type: "string",
91-
label: "File",
92-
description: "The file to upload from the `/tmp` folder. [See the docs here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp) on how to upload a file to `/tmp`.",
91+
label: "File Path or URL",
92+
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`)",
9393
},
9494
name: {
9595
type: "string",

components/pdf4me/actions/compress-pdf/compress-pdf.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import pdf4me from "../../pdf4me.app.mjs";
22
import utils from "../../common/utils.mjs";
3-
import fs from "fs";
43

54
export default {
65
key: "pdf4me-compress-pdf",
76
name: "Compress PDF",
87
description: "Compress a PDF file to reduce its size. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/compress-pdf/)",
9-
version: "0.0.1",
8+
version: "0.1.0",
109
type: "action",
1110
props: {
1211
pdf4me,
@@ -41,10 +40,7 @@ export default {
4140
},
4241
async run({ $ }) {
4342
const filename = utils.checkForExtension(this.filename, "pdf");
44-
const filePath = utils.normalizeFilePath(this.filePath);
45-
const fileContent = fs.readFileSync(filePath, {
46-
encoding: "base64",
47-
});
43+
const fileContent = await utils.getBase64File(this.filePath);
4844

4945
const response = await this.pdf4me.compressPdf({
5046
$,

components/pdf4me/actions/convert-to-pdf/convert-to-pdf.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import pdf4me from "../../pdf4me.app.mjs";
22
import utils from "../../common/utils.mjs";
3-
import fs from "fs";
43

54
export default {
65
key: "pdf4me-convert-to-pdf",
76
name: "Convert to PDF",
87
description: "Convert a document (e.g., DOCX, XLSX, PPTX) to PDF. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/convert-to-pdf/)",
9-
version: "0.0.1",
8+
version: "0.1.0",
109
type: "action",
1110
props: {
1211
pdf4me,
@@ -25,10 +24,7 @@ export default {
2524
},
2625
},
2726
async run({ $ }) {
28-
const filePath = utils.normalizeFilePath(this.filePath);
29-
const fileContent = fs.readFileSync(filePath, {
30-
encoding: "base64",
31-
});
27+
const fileContent = await utils.getBase64File(this.filePath);
3228

3329
const response = await this.pdf4me.convertToPdf({
3430
$,

components/pdf4me/actions/merge-pdfs/merge-pdfs.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import pdf4me from "../../pdf4me.app.mjs";
22
import utils from "../../common/utils.mjs";
3-
import fs from "fs";
43

54
export default {
65
key: "pdf4me-merge-pdfs",
76
name: "Merge PDF Files",
87
description: "Merge multiple PDF files into a single PDF. [See the documentation](https://dev.pdf4me.com/apiv2/documentation/actions/merge/)",
9-
version: "0.0.1",
8+
version: "0.1.0",
109
type: "action",
1110
props: {
1211
pdf4me,
1312
filePaths: {
1413
type: "string[]",
15-
label: "File Paths",
16-
description: "An array of paths to a PDF files in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
14+
label: "File Paths or URLs",
15+
description: "The files to process. For each entry, provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`)",
1716
},
1817
filename: {
1918
propDefinition: [
@@ -24,10 +23,8 @@ export default {
2423
},
2524
async run({ $ }) {
2625
const filename = utils.checkForExtension(this.filename, "pdf");
27-
const filePaths = this.filePaths.map((path) => utils.normalizeFilePath(path));
28-
const fileContents = filePaths.map((path) => fs.readFileSync(path, {
29-
encoding: "base64",
30-
}));
26+
const promises = await Promise.allSettled(this.filePaths.map((p) => utils.getBase64File(p)));
27+
const fileContents = promises.map((prom) => prom.value);
3128

3229
const response = await this.pdf4me.mergePdfs({
3330
$,

components/pdf4me/common/utils.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import fs from "fs";
2-
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
ConfigurationError, getFileStream,
4+
} from "@pipedream/platform";
35

46
function normalizeFilePath(path) {
57
return path.startsWith("/tmp/")
68
? path
79
: `/tmp/${path}`;
810
}
911

10-
function checkForExtension(filename, ext = "pdf") {
11-
return filename.endsWith(`.${ext}`)
12-
? filename
13-
: `${filename}.${ext}`;
14-
}
15-
1612
function downloadToTmp(response, filename) {
1713
const rawcontent = response.toString("base64");
1814
const buffer = Buffer.from(rawcontent, "base64");
@@ -41,9 +37,17 @@ function handleErrorMessage(error) {
4137
throw new ConfigurationError(errorMessage);
4238
}
4339

40+
async function getBase64File(filePath) {
41+
const stream = await getFileStream(filePath);
42+
const chunks = [];
43+
for await (const chunk of stream) {
44+
chunks.push(chunk);
45+
}
46+
return Buffer.concat(chunks).toString("base64");
47+
}
48+
4449
export default {
45-
normalizeFilePath,
46-
checkForExtension,
4750
downloadToTmp,
4851
handleErrorMessage,
52+
getBase64File,
4953
};

0 commit comments

Comments
 (0)