-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - documentpro #12515
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
New Components - documentpro #12515
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e4ba9e
documentpro init
luancazarine c59641d
[Components] documentpro #12498
luancazarine ee91c31
Merge branch 'master' into issue-12498
luancazarine afb478d
pnpm update
luancazarine ad2a3f4
remove form-data import
luancazarine bdd6003
fix formData reference
luancazarine 78922e4
Update components/documentpro/package.json
luancazarine d1ebe6c
pnpm update
luancazarine f3093f0
update package.json
luancazarine 7b50b40
pnpm update
luancazarine 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
41 changes: 41 additions & 0 deletions
41
components/documentpro/actions/new-document/new-document.mjs
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,41 @@ | ||
import FormData from "form-data"; | ||
import fs from "fs"; | ||
import { checkTmp } from "../../common/utils.mjs"; | ||
import documentpro from "../../documentpro.app.mjs"; | ||
|
||
export default { | ||
key: "documentpro-new-document", | ||
name: "Upload New Document", | ||
description: "Uploads a document to DocumentPro's parser. [See the documentation](https://docs.documentpro.ai/docs/using-api/manage-documents/import-files)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
documentpro, | ||
parserId: { | ||
propDefinition: [ | ||
documentpro, | ||
"parserId", | ||
], | ||
}, | ||
document: { | ||
propDefinition: [ | ||
documentpro, | ||
"document", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const formData = new FormData(); | ||
const file = fs.createReadStream(checkTmp(this.document)); | ||
formData.append("file", file); | ||
|
||
const response = await this.documentpro.uploadDocument({ | ||
parserId: this.parserId, | ||
data: formData, | ||
headers: formData.getHeaders(), | ||
}); | ||
|
||
$.export("$summary", `Successfully uploaded document with Id: ${response.request_id}`); | ||
return response; | ||
}, | ||
}; |
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,6 @@ | ||
export const checkTmp = (filename) => { | ||
if (filename.indexOf("/tmp") === -1) { | ||
return `/tmp/${filename}`; | ||
} | ||
return filename; | ||
}; | ||
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 |
---|---|---|
@@ -1,11 +1,71 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "documentpro", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
document: { | ||
type: "string", | ||
label: "Document", | ||
description: "The path to the 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).", | ||
}, | ||
parserId: { | ||
type: "string", | ||
label: "Parser ID", | ||
description: "The ID of the parser to use for uploading the document", | ||
async options() { | ||
const { items } = await this.getParsers(); | ||
return items.map(({ | ||
template_title: label, template_id: value, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.documentpro.ai"; | ||
}, | ||
_headers(headers = {}) { | ||
return { | ||
...headers, | ||
"x-api-key": this.$auth.api_key, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path = "", headers, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(headers), | ||
...opts, | ||
}); | ||
}, | ||
getParsers(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/v1/templates", | ||
...opts, | ||
}); | ||
}, | ||
updateParser({ | ||
parserId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "PUT", | ||
path: `/v1/templates/${parserId}`, | ||
...opts, | ||
}); | ||
}, | ||
uploadDocument({ | ||
parserId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/files/upload/${parserId}`, | ||
...opts, | ||
}); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/documentpro", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream DocumentPro Components", | ||
"main": "documentpro.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,9 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.0", | ||
"form-data": "^4.0.0" | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
components/documentpro/sources/new-document-updated-instant/new-document-updated-instant.mjs
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,58 @@ | ||
import documentpro from "../../documentpro.app.mjs"; | ||
import sampleEmit from "./test-event.mjs"; | ||
|
||
export default { | ||
key: "documentpro-new-document-updated-instant", | ||
name: "New Document Updated (Instant)", | ||
description: "Emit new event when a file request status changes. You can only create one webhook in a parser at a time.", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
documentpro, | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: true, | ||
}, | ||
db: "$.service.db", | ||
parserId: { | ||
propDefinition: [ | ||
documentpro, | ||
"parserId", | ||
], | ||
}, | ||
}, | ||
hooks: { | ||
async activate() { | ||
await this.documentpro.updateParser({ | ||
parserId: this.parserId, | ||
data: { | ||
webhook_url: this.http.endpoint, | ||
}, | ||
}); | ||
}, | ||
async deactivate() { | ||
await this.documentpro.updateParser({ | ||
parserId: this.parserId, | ||
data: { | ||
webhook_url: null, | ||
}, | ||
}); | ||
}, | ||
}, | ||
async run({ body }) { | ||
this.$emit(body, { | ||
id: `${body.data.request_id}-${body.timestamp}`, | ||
summary: `New document (${body.data.response_body.file_name}) status updated: ${body.event} - ${body.data.request_status}`, | ||
ts: Date.parse(body.timestamp), | ||
}); | ||
|
||
this.http.respond({ | ||
status: 200, | ||
body: { | ||
message: "Received", | ||
}, | ||
}); | ||
}, | ||
sampleEmit, | ||
}; |
20 changes: 20 additions & 0 deletions
20
components/documentpro/sources/new-document-updated-instant/test-event.mjs
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,20 @@ | ||
export default { | ||
"event": "file_request_status_change", | ||
"timestamp": "2023-07-30T19:05:29.565249", | ||
"data": { | ||
"request_id": "your-request-id", | ||
"request_status": "completed", | ||
"response_body": { | ||
"file_name": "your-file-name", | ||
"file_presigned_url": "temporary-url-to-your-file", | ||
"user_error_msg": null, | ||
"template_id": "your-template-id", | ||
"template_type": "receipt", | ||
"template_title": "Receipt", | ||
"num_pages": 2, | ||
"result_json_data": {} | ||
}, | ||
"created_at": "2023-07-30T19:05:10.696893", | ||
"updated_at": "2023-07-30T19:05:29.565249" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.