-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* agrello init * [Components] agrello #13863 Sources - New Signature (Instant) - New Signed Document (Instant) - New Document Actions - Get Document * pnpm update * Fix Summary * Update components/agrello/sources/new-signature-instant/new-signature-instant.mjs Co-authored-by: Leo Vu <[email protected]> --------- Co-authored-by: Leo Vu <[email protected]>
- Loading branch information
1 parent
309ccbb
commit d5a3176
Showing
12 changed files
with
469 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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; | ||
}; |
This file contains 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 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 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.