Skip to content

Commit 8636bd2

Browse files
committed
add: xero_accounting_api, zerobounce, zip_archive_api
1 parent 747949b commit 8636bd2

File tree

7 files changed

+57
-63
lines changed

7 files changed

+57
-63
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// legacy_hash_id: a_B0i8rE
2-
import fs from "fs";
32
import FormData from "form-data";
4-
import { axios } from "@pipedream/platform";
3+
import {
4+
axios, getFileStreamAndMetadata,
5+
} from "@pipedream/platform";
56

67
export default {
78
key: "xero_accounting_api-upload-file",
89
name: "Upload File",
910
description: "Uploads a file to the specified document.",
10-
version: "0.2.1",
11+
version: "1.0.0",
1112
type: "action",
1213
props: {
1314
xero_accounting_api: {
@@ -18,9 +19,10 @@ export default {
1819
type: "string",
1920
description: "Id of the organization tenant to use on the Xero Accounting API. See [Get Tenant Connections](https://pipedream.com/@sergio/xero-accounting-api-get-tenant-connections-p_OKCzOgn/edit) for a workflow example on how to pull this data.",
2021
},
21-
attachment_filename: {
22+
filePathOrUrl: {
2223
type: "string",
23-
description: "Name of the file to upload as an attachment to the Xero document.",
24+
label: "File Path or URL",
25+
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`)",
2426
},
2527
document_type: {
2628
type: "string",
@@ -50,17 +52,24 @@ export default {
5052
throw new Error("Must provide tenant_id parameter.");
5153
}
5254

53-
let data = new FormData();
54-
const file = fs.createReadStream(`/tmp/${this.attachment_filename}`);
55-
data.append("file", file);
55+
const {
56+
stream, metadata,
57+
} = await getFileStreamAndMetadata(this.filePathOrUrl);
58+
const data = new FormData();
59+
data.append("file", stream, {
60+
contentType: metadata.contentType,
61+
knownLength: metadata.size,
62+
filename: metadata.name,
63+
});
5664

5765
//Sends the request against Xero Accounting API
5866
return await axios($, {
5967
method: "post",
60-
url: `https://api.xero.com/api.xro/2.0/${this.document_type}/${this.document_id}/Attachments/${attachment_filename}`,
68+
url: `https://api.xero.com/api.xro/2.0/${this.document_type}/${this.document_id}/Attachments/${metadata.name}`,
6169
headers: {
6270
"Authorization": `Bearer ${this.xero_accounting_api.$auth.oauth_access_token}`,
6371
"xero-tenant-id": this.tenant_id,
72+
...data.getHeaders(),
6473
},
6574
data,
6675
});

components/xero_accounting_api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/xero_accounting_api",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "Pipedream Xero Components",
55
"main": "xero_accounting_api.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/xero_accounting_api",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^1.4.0"
13+
"@pipedream/platform": "^3.1.0"
1414
},
1515
"publishConfig": {
1616
"access": "public"

components/zerobounce/actions/file-validation/file-validation.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import zerobounce from "../../zerobounce.app.mjs";
2-
import fs from "fs";
32
import FormData from "form-data";
4-
import path from "path";
3+
import { getFileStreamAndMetadata } from "@pipedream/platform";
54

65
export default {
76
key: "zerobounce-file-validation",
87
name: "Validate Emails in File",
98
description: "Performs email validation on all the addresses contained in a provided file. [See the documentation](https://www.zerobounce.net/docs/email-validation-api-quickstart/)",
10-
version: "0.0.1",
9+
version: "0.1.0",
1110
type: "action",
1211
props: {
1312
zerobounce,
1413
filePath: {
1514
type: "string",
16-
label: "File Path",
17-
description: "The path to a csv or txt file 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)",
15+
label: "File Path or URL",
16+
description: "The csv or txt file to validate. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.csv`)",
1817
},
1918
emailAddressColumn: {
2019
type: "integer",
@@ -74,14 +73,15 @@ export default {
7473
({ resume_url: returnUrl } = $.flow.rerun(600000, null, 1));
7574
}
7675

77-
const filePath = this.filePath.includes("tmp/")
78-
? this.filePath
79-
: `/tmp/${this.filePath}`;
80-
const fileName = path.basename(filePath);
81-
const fileContent = fs.readFileSync(filePath);
82-
76+
const {
77+
stream, metadata,
78+
} = await getFileStreamAndMetadata(this.filePath);
8379
const formData = new FormData();
84-
formData.append("file", fileContent, fileName);
80+
formData.append("file", stream, {
81+
contentType: metadata.contentType,
82+
knownLength: metadata.size,
83+
filename: metadata.name,
84+
});
8585
formData.append("email_address_column", this.emailAddressColumn);
8686
formData.append("api_key", this.zerobounce.$auth.api_key);
8787
if (this.firstNameColumn) {

components/zerobounce/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zerobounce",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream ZeroBounce Components",
55
"main": "zerobounce.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.1",
1818
"path": "^0.12.7"
1919
}

components/zip_archive_api/actions/compress-files/compress-files.mjs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import app from "../../zip_archive_api.app.mjs";
2-
import fs from "fs";
32
import FormData from "form-data";
3+
import {
4+
getFileStreamAndMetadata, writeFile,
5+
} from "@pipedream/platform";
46

57
export default {
68
key: "zip_archive_api-compress-files",
79
name: "Compress Files",
810
description: "Compress files provided through URLs into a zip folder. [See the documentation](https://archiveapi.com/rest-api/file-compression/)",
9-
version: "0.0.1",
11+
version: "0.1.0",
1012
type: "action",
1113
props: {
1214
app,
13-
uploadType: {
14-
propDefinition: [
15-
app,
16-
"uploadType",
17-
],
18-
},
1915
archiveName: {
2016
propDefinition: [
2117
app,
@@ -42,38 +38,32 @@ export default {
4238
},
4339
},
4440
async run({ $ }) {
45-
let data = {
46-
files: this.files,
47-
archiveName: this.archiveName,
48-
compressionLevel: this.compressionLevel,
49-
password: this.password,
50-
};
51-
52-
if (this.uploadType === "File") {
53-
data = new FormData();
41+
const data = new FormData();
5442

55-
if (this.password) data.append("Password", this.password);
56-
if (this.compressionLevel) data.append("CompressionLevel", this.compressionLevel);
57-
data.append("ArchiveName", this.archiveName);
43+
if (this.password) data.append("Password", this.password);
44+
if (this.compressionLevel) data.append("CompressionLevel", this.compressionLevel);
45+
data.append("ArchiveName", this.archiveName);
5846

59-
for (const file of this.files) {
60-
data.append("Files", fs.createReadStream(file));
61-
}
47+
for (const file of this.files) {
48+
const {
49+
stream, metadata,
50+
} = await getFileStreamAndMetadata(file);
51+
data.append("Files", stream, {
52+
contentType: metadata.contentType,
53+
knownLength: metadata.size,
54+
filename: metadata.name,
55+
});
6256
}
6357

64-
const headers = this.uploadType === "File"
65-
? data.getHeaders()
66-
: {};
67-
6858
const response = await this.app.compressFiles({
6959
$,
7060
data,
71-
headers,
61+
headers: data.getHeaders(),
7262
responseType: "arraybuffer",
7363
});
7464

7565
const tmpPath = `/tmp/${this.archiveName}`;
76-
fs.writeFileSync(tmpPath, response);
66+
await writeFile(tmpPath, response);
7767

7868
$.export("$summary", `Successfully compressed the files into '${tmpPath}'`);
7969

components/zip_archive_api/package.json

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

components/zip_archive_api/zip_archive_api.app.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ export default {
3030
},
3131
files: {
3232
type: "string[]",
33-
label: "Files URLs",
34-
description: "The URLs or path of the files to be compressed",
35-
},
36-
file: {
37-
type: "string",
38-
label: "File URL",
39-
description: "The URL or path of the archive to extract the files from",
33+
label: "File Paths or URLs",
34+
description: "The files to upload. For each entry, provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
4035
},
4136
},
4237
methods: {

0 commit comments

Comments
 (0)