-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expensify - export report #18320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Expensify - export report #18320
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
17c0b6f
new component
michelle0927 a20228c
Merge remote-tracking branch 'origin/master' into issue-18191
michelle0927 f0e9a8b
versions
michelle0927 2d0c404
updates
michelle0927 655b46d
updates
michelle0927 f1b6fad
updates
michelle0927 1f7dc95
updates
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
components/expensify/actions/export-report/export-report.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,247 @@ | ||
| import { defineAction } from "@pipedream/types"; | ||
| import expensify from "../../app/expensify.app"; | ||
| import fs from "fs"; | ||
| import { | ||
| axios, ConfigurationError, | ||
| } from "@pipedream/platform"; | ||
| import qs from "qs"; | ||
|
|
||
| export default defineAction({ | ||
| key: "expensify-export-report", | ||
| name: "Export Report", | ||
| description: "Export Expensify reports to a file (csv, xls, xlsx, txt, pdf, json, xml). [See the documentation](https://integrations.expensify.com/Integration-Server/doc/#report-exporter)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| expensify, | ||
| reportIds: { | ||
| type: "string[]", | ||
| label: "Report IDs", | ||
| description: "The IDs of the reports to be exported. Required if `startDate` or `approvedAfter` are not specified.", | ||
| optional: true, | ||
| }, | ||
| startDate: { | ||
| type: "string", | ||
| label: "Start Date", | ||
| description: "The start date of the report. Format: YYYY-MM-DD. Required if `reportIds` or `approvedAfter ` are not specified.", | ||
| optional: true, | ||
| }, | ||
| endDate: { | ||
| type: "string", | ||
| label: "End Date", | ||
| description: "The end date of the report. Format: YYYY-MM-DD. Conditionally required, if either `startDate` or `approvedAfter` is more than one year ago.", | ||
| optional: true, | ||
| }, | ||
| approvedAfter: { | ||
| type: "string", | ||
| label: "Approved After", | ||
| description: "Filters out all reports approved before the given date, whichever occurred last (inclusive). Required if `reportIds` or `startDate` are not specified", | ||
| optional: true, | ||
| }, | ||
| fileExtension: { | ||
| type: "string", | ||
| label: "File Extension", | ||
| description: "Specifies the format of the generated report", | ||
| options: [ | ||
| "csv", | ||
| "xls", | ||
| "xlsx", | ||
| "txt", | ||
| "pdf", | ||
| "json", | ||
| "xml", | ||
| ], | ||
| }, | ||
| markedAsExported: { | ||
| type: "string", | ||
| label: "Marked as Exported Label (Filter)", | ||
| description: "Filters out reports that have already been exported with that label", | ||
| optional: true, | ||
| }, | ||
| reportStates: { | ||
| type: "string[]", | ||
| label: "Report States", | ||
| description: "Only the reports matching the specified status(es) will be exported", | ||
| options: [ | ||
| "OPEN", | ||
| "SUBMITTED", | ||
| "APPROVED", | ||
| "REIMBURSED", | ||
| "ARCHIVED", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| employeeEmail: { | ||
| type: "string", | ||
| label: "Employee Email", | ||
| description: "Export reports for the specified employee email", | ||
| optional: true, | ||
| }, | ||
| policyIds: { | ||
| propDefinition: [ | ||
| expensify, | ||
| "policyExportIds", | ||
| ], | ||
| }, | ||
| fileBaseName: { | ||
| type: "string", | ||
| label: "File Base Name", | ||
| description: "The base name of the file to be exported", | ||
| optional: true, | ||
| }, | ||
| includeFullPageReceiptsPdf: { | ||
| type: "boolean", | ||
| label: "Include Full Page Receipts PDF", | ||
| description: "Specifies whether generated PDFs should include full page receipts. This parameter is used only if fileExtension contains pdf.", | ||
| optional: true, | ||
| }, | ||
| emailRecipients: { | ||
| type: "string[]", | ||
| label: "Email Recipients", | ||
| description: "People to email at the end of the export", | ||
| optional: true, | ||
| }, | ||
| markAsExported: { | ||
| type: "string", | ||
| label: "Mark as Exported", | ||
| description: "Mark the reports as exported with the given label", | ||
| optional: true, | ||
| }, | ||
| templatePath: { | ||
| type: "string", | ||
| label: "Template Path", | ||
| description: "The path in the /tmp directory to the template to use for the export. Required if `fileExtension` is `csv`, `txt`, `json`, or `xml`.", | ||
| optional: true, | ||
| }, | ||
| limit: { | ||
| type: "string", | ||
| label: "Limit", | ||
| description: "Maximum number of reports to export", | ||
| optional: true, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| test: { | ||
| type: "boolean", | ||
| label: "Test Mode", | ||
| description: "If set to true, actions defined in `onFinish` (i.e. email, markAsExported) will not be executed", | ||
| optional: true, | ||
| }, | ||
| syncDir: { | ||
| type: "dir", | ||
| accessMode: "write", | ||
| sync: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.reportIds && !this.startDate && !this.approvedAfter) { | ||
| throw new ConfigurationError("At least one of `reportIds`, `startDate`, or `approvedAfter` must be specified"); | ||
| } | ||
|
|
||
| if ([ | ||
| "csv", | ||
| "txt", | ||
| "json", | ||
| "xml", | ||
| ].includes(this.fileExtension) && !this.templatePath) { | ||
| throw new ConfigurationError(`Template path is required for file extension: ${this.fileExtension}`); | ||
| } | ||
|
|
||
| const onFinish = []; | ||
| if (this.emailRecipients) { | ||
| onFinish.push({ | ||
| actionName: "email", | ||
| recipients: this.emailRecipients.join(","), | ||
| }); | ||
| } | ||
|
|
||
| if (this.markAsExported) { | ||
| onFinish.push({ | ||
| actionName: "markAsExported", | ||
| label: this.markAsExported, | ||
| }); | ||
| } | ||
|
|
||
| const data = { | ||
| type: "file", | ||
| credentials: { | ||
| partnerUserID: this.expensify._partnerUserId(), | ||
| partnerUserSecret: this.expensify._partnerUserSecret(), | ||
| }, | ||
| onReceive: { | ||
| immediateResponse: [ | ||
| "returnRandomFileName", | ||
| ], | ||
| }, | ||
| inputSettings: { | ||
| type: "combinedReportData", | ||
| filters: { | ||
| reportIDList: this.reportIds | ||
| ? this.reportIds.join(",") | ||
| : undefined, | ||
| startDate: this.startDate, | ||
| endDate: this.endDate, | ||
| approvedAfter: this.approvedAfter, | ||
| markedAsExported: this.markedAsExported, | ||
| policyIDList: this.policyIds | ||
| ? this.policyIds.join(",") | ||
| : undefined, | ||
| }, | ||
| reportState: this.reportStates | ||
| ? this.reportStates.join(",") | ||
| : undefined, | ||
| employeeEmail: this.employeeEmail, | ||
| limit: this.limit, | ||
| }, | ||
| outputSettings: { | ||
| fileExtension: this.fileExtension, | ||
| fileBasename: this.fileBaseName, | ||
| includeFullPageReceiptsPdf: this.includeFullPageReceiptsPdf, | ||
| }, | ||
| onFinish, | ||
| test: this.test, | ||
| }; | ||
|
|
||
| let fileName; | ||
| const args = { | ||
| method: "post", | ||
| url: `${this.expensify._apiUrl()}`, | ||
| }; | ||
|
|
||
| if (!this.templatePath) { | ||
| fileName = await axios($, { | ||
| ...args, | ||
| data: qs.stringify({ | ||
| requestJobDescription: JSON.stringify(data), | ||
| template: "default", | ||
| }), | ||
| }); | ||
| } else { | ||
| fileName = await axios($, { | ||
| ...args, | ||
| data: qs.stringify({ | ||
| requestJobDescription: JSON.stringify(data), | ||
| template: fs.readFileSync(this.templatePath.includes("tmp/") | ||
| ? this.templatePath | ||
| : `/tmp/${this.templatePath}`, "utf8"), | ||
| }), | ||
| headers: { | ||
| "Content-Type": "application/x-www-form-urlencoded", | ||
| }, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const fileBuffer = await this.expensify.downloadFile({ | ||
| $, | ||
| fileName, | ||
| }); | ||
|
|
||
| const path = `/tmp/${fileName}`; | ||
|
|
||
| await fs.writeFileSync(path, fileBuffer); | ||
|
|
||
| if (fileBuffer) { | ||
| $.export("$summary", `Successfully exported report in ${path}`); | ||
| } | ||
|
|
||
| return path; | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.