Skip to content

Commit a5578fc

Browse files
committed
wip
1 parent 6e80efa commit a5578fc

File tree

7 files changed

+272
-6
lines changed

7 files changed

+272
-6
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
2+
3+
export default {
4+
key: "xero_accounting_api-delete-file",
5+
name: "Delete File",
6+
description: "Delete a file. [See the documentation](https://developer.xero.com/documentation/api/files/files#delete-files)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
xeroAccountingApi,
11+
fileId: {
12+
propDefinition: [
13+
xeroAccountingApi,
14+
"fileId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.xeroAccountingApi.deleteFile({
20+
$,
21+
fileId: this.fileId,
22+
});
23+
$.export("$summary", `Successfully deleted file with ID: ${this.fileId}`);
24+
return response;
25+
},
26+
};
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
2+
3+
export default {
4+
key: "xero_accounting_api-list-files",
5+
name: "List Files",
6+
description: "List files. [See the documentation](https://developer.xero.com/documentation/api/files/files#get-files)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
xeroAccountingApi,
11+
pagesize: {
12+
type: "integer",
13+
label: "Page Size",
14+
description: "The number of records returned within a single API call",
15+
optional: true,
16+
default: 100,
17+
min: 1,
18+
max: 100,
19+
},
20+
page: {
21+
type: "integer",
22+
label: "Page",
23+
description: "The page number of the current page in the returned records",
24+
optional: true,
25+
default: 1,
26+
},
27+
sort: {
28+
type: "string",
29+
label: "Sort",
30+
description: "The field to sort the records by",
31+
optional: true,
32+
options: [
33+
"Name",
34+
"Size",
35+
"CreatedDateUTC",
36+
],
37+
},
38+
direction: {
39+
type: "string",
40+
label: "Direction",
41+
description: "The direction to sort the records by",
42+
optional: true,
43+
options: [
44+
"ASC",
45+
"DESC",
46+
],
47+
},
48+
},
49+
async run({ $ }) {
50+
const { Items: items } = await this.xeroAccountingApi.listFiles({
51+
$,
52+
params: {
53+
pageSize: this.pagesize,
54+
page: this.page,
55+
sort: this.sort,
56+
direction: this.direction,
57+
},
58+
});
59+
60+
$.export("$summary", `Successfully retrieved ${items.length} file${items.length === 1
61+
? ""
62+
: "s"}`);
63+
return items;
64+
},
65+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
2+
3+
export default {
4+
key: "xero_accounting_api-update-file",
5+
name: "Update File",
6+
description: "Rename a file or move it to a different folder. [See the documentation](https://developer.xero.com/documentation/api/files/files#put-files)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
xeroAccountingApi,
11+
fileId: {
12+
propDefinition: [
13+
xeroAccountingApi,
14+
"fileId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "The new name of the file",
21+
optional: true,
22+
},
23+
folderId: {
24+
propDefinition: [
25+
xeroAccountingApi,
26+
"folderId",
27+
],
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.xeroAccountingApi.updateFile(this.fileId, {
33+
$,
34+
data: {
35+
Name: this.name,
36+
FolderId: this.folderId,
37+
},
38+
});
39+
$.export("$summary", `Successfully updated file with ID: ${this.fileId}`);
40+
return response;
41+
},
42+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
3+
import FormData from "form-data";
4+
5+
export default {
6+
key: "xero_accounting_api-upload-file-to-folder",
7+
name: "Upload File to Folder",
8+
description: "Upload a file to a folder. [See the documentation](https://developer.xero.com/documentation/api/files/files#post-files)",
9+
version: "0.0.{{ts}}",
10+
type: "action",
11+
props: {
12+
xeroAccountingApi,
13+
filePathOrUrl: {
14+
type: "string",
15+
label: "File Path or URL",
16+
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`)",
17+
},
18+
folderId: {
19+
propDefinition: [
20+
xeroAccountingApi,
21+
"folderId",
22+
],
23+
},
24+
syncDir: {
25+
type: "dir",
26+
accessMode: "read",
27+
sync: true,
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
stream, metadata,
34+
} = await getFileStreamAndMetadata(this.filePathOrUrl);
35+
36+
const data = new FormData();
37+
data.append("Xero", stream, {
38+
contentType: metadata.contentType,
39+
knownLength: metadata.size,
40+
filename: metadata.name,
41+
});
42+
43+
const response = await this.xeroAccountingApi.uploadFileToFolder({
44+
$,
45+
folderId: this.folderId,
46+
data,
47+
headers: data.getHeaders(),
48+
});
49+
50+
$.export("$summary", `Successfully uploaded file to folder with ID: ${this.folderId}`);
51+
return response;
52+
},
53+
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import xeroAccountingApi from "../../xero_accounting_api.app.mjs";
33

44
export default {
55
key: "xero_accounting_api-upload-file",
6-
name: "Upload File",
6+
name: "Upload File (Attachment)",
77
description: "Uploads a file to the specified document. [See the documentation](https://developer.xero.com/documentation/api/accounting/invoices#upload-attachment)",
8-
version: "1.0.2",
8+
version: "1.0.3",
99
type: "action",
1010
props: {
1111
xeroAccountingApi,
@@ -64,7 +64,7 @@ export default {
6464
} = await getFileStreamAndMetadata(this.filePathOrUrl);
6565
const fileBinary = await this.streamToBuffer(stream);
6666

67-
const response = await this.xeroAccountingApi.uploadFile({
67+
const response = await this.xeroAccountingApi.uploadAttachment({
6868
$,
6969
tenantId: this.tenantId,
7070
documentType: this.documentType,

components/xero_accounting_api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"homepage": "https://pipedream.com/apps/xero_accounting_api",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^3.1.0"
13+
"@pipedream/platform": "^3.1.0",
14+
"form-data": "^4.0.4"
1415
},
1516
"publishConfig": {
1617
"access": "public"

components/xero_accounting_api/xero_accounting_api.app.mjs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,38 @@ export default {
7777
label: "Line items",
7878
description: "The LineItems collection can contain any number of individual LineItem sub-elements. At least one is required to create a complete Invoice. [Refer to Tax Type](https://developer.xero.com/documentation/api/accounting/types#report-tax-types), [Refer to Line Items](https://developer.xero.com/documentation/api/accounting/invoices#creating-updating-and-deleting-line-items-when-updating-invoices)\n\n**Example:** `[{\"Description\":\"Football\", \"Quantity\":\"20\", \"UnitAmount\":\"50000\", \"TaxType\":\"OUTPUT\" }]`",
7979
},
80+
fileId: {
81+
type: "string",
82+
label: "File ID",
83+
description: "Unique identification of the file",
84+
async options({ page }) {
85+
const { Items: items } = await this.listFiles({
86+
params: {
87+
page: page + 1,
88+
},
89+
});
90+
return items?.map(({
91+
Id: value, Name: label,
92+
}) => ({
93+
label,
94+
value,
95+
})) || [];
96+
},
97+
},
98+
folderId: {
99+
type: "string",
100+
label: "Folder ID",
101+
description: "Unique identification of the folder",
102+
async options() {
103+
const folders = await this.listFolders();
104+
return folders?.map(({
105+
Id: value, Name: label,
106+
}) => ({
107+
label,
108+
value,
109+
})) || [];
110+
},
111+
},
80112
},
81113
methods: {
82114
setLastDateChecked(db, value) {
@@ -102,10 +134,13 @@ export default {
102134
modifiedSince,
103135
path,
104136
headers,
137+
isFilesApi = false,
105138
...opts
106139
}) {
107140
return axios($, {
108-
url: `${BASE_URL}/api.xro/2.0${path}`,
141+
url: `${BASE_URL}${(isFilesApi
142+
? "/files.xro/1.0"
143+
: "/api.xro/2.0")}${path}`,
109144
headers: this.getHeader({
110145
tenantId,
111146
modifiedSince,
@@ -356,7 +391,7 @@ export default {
356391
...opts,
357392
});
358393
},
359-
uploadFile({
394+
uploadAttachment({
360395
documentType, documentId, fileName, ...opts
361396
}) {
362397
return this._makeRequest({
@@ -388,5 +423,49 @@ export default {
388423
...opts,
389424
});
390425
},
426+
listFiles(opts = {}) {
427+
return this._makeRequest({
428+
path: "/Files",
429+
isFilesApi: true,
430+
...opts,
431+
});
432+
},
433+
uploadFileToFolder({
434+
folderId, ...opts
435+
}) {
436+
return this._makeRequest({
437+
method: "POST",
438+
path: `/Files/${folderId}`,
439+
isFilesApi: true,
440+
...opts,
441+
});
442+
},
443+
updateFile({
444+
fileId, ...opts
445+
}) {
446+
return this._makeRequest({
447+
method: "PUT",
448+
path: `/Files/${fileId}`,
449+
isFilesApi: true,
450+
...opts,
451+
});
452+
},
453+
deleteFile({
454+
fileId, ...opts
455+
}) {
456+
return this._makeRequest({
457+
method: "DELETE",
458+
path: `/Files/${fileId}`,
459+
isFilesApi: true,
460+
...opts,
461+
});
462+
},
463+
listFolders(opts = {}) {
464+
return this._makeRequest({
465+
path: "/Folders",
466+
isFilesApi: true,
467+
...opts,
468+
});
469+
},
391470
},
392471
};

0 commit comments

Comments
 (0)