-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - agrello #13875
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 - agrello #13875
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4d26ca
agrello init
luancazarine 6f55115
[Components] agrello #13863
luancazarine a61dd11
pnpm update
luancazarine 050194d
Merge branch 'master' into issue-13863
luancazarine 548a429
Fix Summary
vunguyenhung 54c2ba7
Update components/agrello/sources/new-signature-instant/new-signature…
luancazarine e9312db
Merge branch 'master' into issue-13863
luancazarine 90369cb
Merge branch 'master' into issue-13863
luancazarine af43fbd
Merge branch 'master' into issue-13863
luancazarine dd046c2
Merge branch 'master' into issue-13863
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
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,35 @@ | ||
| import agrello from "../../agrello.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "agrello-get-document", | ||
| name: "Get Document", | ||
| description: "Get a document in Agrello. [See the documentation](https://api.agrello.io/public/webjars/swagger-ui/index.html)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| agrello, | ||
| folderId: { | ||
| propDefinition: [ | ||
| agrello, | ||
| "folderId", | ||
| ], | ||
| }, | ||
| documentId: { | ||
| propDefinition: [ | ||
| agrello, | ||
| "documentId", | ||
| ({ folderId }) => ({ | ||
| folderId, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.agrello.getDocument({ | ||
| $, | ||
| documentId: this.documentId, | ||
| }); | ||
| $.export("$summary", `Successfully retrieved document with ID ${this.documentId}`); | ||
| 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 |
|---|---|---|
| @@ -1,11 +1,144 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "agrello", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| folderId: { | ||
| type: "string", | ||
| label: "Folder ID", | ||
| description: "The ID of the folder", | ||
| async options({ page }) { | ||
| return await this.listFolders({ | ||
| params: { | ||
| page, | ||
| }, | ||
| }); | ||
| }, | ||
| }, | ||
| documentId: { | ||
| type: "string", | ||
| label: "Document ID", | ||
| description: "The ID of the document", | ||
| async options({ | ||
| folderId, page, | ||
| }) { | ||
| const { content } = await this.listDocuments({ | ||
| folderId, | ||
| params: { | ||
| page, | ||
| }, | ||
| }); | ||
| return content.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.agrello.io/public/v3"; | ||
| }, | ||
| _headers(headers = {}) { | ||
| return { | ||
| ...headers, | ||
| Authorization: `Bearer ${this.$auth.oauth_access_token}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, headers, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(headers), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async listFolders() { | ||
| const { content } = await this._makeRequest({ | ||
| path: "/folders", | ||
| }); | ||
|
|
||
| const folders = []; | ||
| for (const parent of content) { | ||
| folders.push({ | ||
| label: `${parent.name}`, | ||
| value: parent.id, | ||
| }); | ||
| folders.push(...await this.getSubFolders(parent.name, parent.id)); | ||
| } | ||
|
|
||
| return folders; | ||
|
|
||
| }, | ||
| async getSubFolders(parentName, parentId) { | ||
| const folders = []; | ||
| const { subspaces } = await this._makeRequest({ | ||
| path: `/folders/${parentId}/folders`, | ||
| }); | ||
| for (const folder of subspaces) { | ||
| const label = `${parentName} - ${folder.name}`; | ||
| folders.push({ | ||
| label, | ||
| value: folder.id, | ||
| }); | ||
| folders.push(...await this.getSubFolders(label, folder.id)); | ||
| } | ||
| return folders; | ||
| }, | ||
| listDocuments({ | ||
| folderId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/folders/${folderId}/containers`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getDocument({ documentId }) { | ||
| return this._makeRequest({ | ||
| path: `/containers/${documentId}`, | ||
| }); | ||
| }, | ||
| createWebhook(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/webhooks", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| deleteWebhook(hookId) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: `/webhooks/${hookId}`, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, maxResults = null, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let count = 0; | ||
| let page = 0; | ||
|
|
||
| do { | ||
| params.page = page++; | ||
| const { content } = await fn({ | ||
| params, | ||
| ...opts, | ||
| }); | ||
| for (const d of content) { | ||
| yield d; | ||
|
|
||
| if (maxResults && ++count === maxResults) { | ||
| return count; | ||
| } | ||
| } | ||
|
|
||
| hasMore = content.length; | ||
|
|
||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
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,31 @@ | ||
| export const checkTmp = (filename) => { | ||
| if (!filename.startsWith("/tmp")) { | ||
| return `/tmp/${filename}`; | ||
| } | ||
| return filename; | ||
| }; | ||
|
|
||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
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/agrello", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Agrello Components", | ||
| "main": "agrello.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.1" | ||
| } | ||
| } | ||
| } | ||
|
|
||
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,44 @@ | ||
| import agrello from "../../agrello.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| agrello, | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: false, | ||
| }, | ||
| db: "$.service.db", | ||
| }, | ||
| methods: { | ||
| _setHookId(hookId) { | ||
| this.db.set("webhookId", hookId); | ||
| }, | ||
| _getHookId() { | ||
| return this.db.get("webhookId"); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const data = await this.agrello.createWebhook({ | ||
| data: { | ||
| event: this.getEvent(), | ||
| url: this.http.endpoint, | ||
| }, | ||
| }); | ||
|
|
||
| this._setHookId(data.id); | ||
| }, | ||
| async deactivate() { | ||
| const webhookId = this._getHookId(); | ||
| await this.agrello.deleteWebhook(webhookId); | ||
| }, | ||
| }, | ||
| async run({ body: { event } }) { | ||
| const ts = Date.parse(new Date()); | ||
| this.$emit(event, { | ||
| id: `${event.containerId}-${ts}`, | ||
| summary: this.getSummary(event), | ||
| ts: 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,78 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import agrello from "../../agrello.app.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| key: "agrello-new-document", | ||
| name: "New Document Added to Folder", | ||
| description: "Emit new event when a user adds a document to a specific folder. [See the documentation](https://api.agrello.io/public/webjars/swagger-ui/index.html)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| agrello, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| folderId: { | ||
| propDefinition: [ | ||
| agrello, | ||
| "folderId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || 0; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
|
|
||
| const response = this.agrello.paginate({ | ||
| fn: this.agrello.listDocuments, | ||
| folderId: this.folderId, | ||
| params: { | ||
| sort: "createdAt,DESC", | ||
| }, | ||
| maxResults, | ||
| }); | ||
|
|
||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| if (Date.parse(item.createdAt) <= lastDate) break; | ||
| responseArray.push(item); | ||
| } | ||
|
|
||
| if (responseArray.length) { | ||
| if (maxResults && (responseArray.length > maxResults)) { | ||
| responseArray.length = maxResults; | ||
| } | ||
| this._setLastDate(Date.parse(responseArray[0].createdAt)); | ||
| } | ||
|
|
||
| for (const item of responseArray.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.id, | ||
| summary: `New Document: ${item.name}`, | ||
| ts: Date.parse(item.createdAt), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| sampleEmit, | ||
| }; |
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.