-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - guru #16623
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 - guru #16623
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
components/guru/actions/add-tag-to-card/add-tag-to-card.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,37 @@ | ||
import guru from "../../guru.app.mjs"; | ||
|
||
export default { | ||
key: "guru-add-tag-to-card", | ||
name: "Add Tag to Card", | ||
description: "Links an existing tag to a specified card in Guru. [See the documentation](https://developer.getguru.com/reference/getv1cardsgetextendedfact)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
guru, | ||
cardId: { | ||
propDefinition: [ | ||
guru, | ||
"cardId", | ||
], | ||
}, | ||
tags: { | ||
propDefinition: [ | ||
guru, | ||
"tags", | ||
], | ||
type: "string", | ||
label: "Tag", | ||
description: "The ID of the tag to add to the card", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.guru.linkTagToCard({ | ||
$, | ||
cardId: this.cardId, | ||
tagId: this.tags, | ||
}); | ||
|
||
$.export("$summary", `Successfully linked tag ${this.tags} to card ${this.cardId}`); | ||
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,70 @@ | ||
import { SHARE_STATUS_OPTIONS } from "../../common/constants.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import guru from "../../guru.app.mjs"; | ||
|
||
export default { | ||
key: "guru-create-card", | ||
name: "Create Card", | ||
description: "Creates a new card on your Guru account. [See the documentation](https://developer.getguru.com/reference/postv1cardscreateextendedfact)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
guru, | ||
title: { | ||
type: "string", | ||
label: "Card Title", | ||
description: "The title of the card to create", | ||
}, | ||
content: { | ||
type: "string", | ||
label: "Content", | ||
description: "The content of the card to create", | ||
}, | ||
shareStatus: { | ||
type: "string", | ||
label: "Share Status", | ||
description: "The share status of the card.", | ||
options: SHARE_STATUS_OPTIONS, | ||
optional: true, | ||
}, | ||
collection: { | ||
propDefinition: [ | ||
guru, | ||
"collection", | ||
], | ||
}, | ||
folderIds: { | ||
propDefinition: [ | ||
guru, | ||
"folderIds", | ||
], | ||
}, | ||
tags: { | ||
propDefinition: [ | ||
guru, | ||
"tags", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.guru.createCard({ | ||
$, | ||
data: { | ||
preferredPhrase: this.title, | ||
content: this.content, | ||
shareStatus: this.shareStatus, | ||
collection: { | ||
id: this.collection, | ||
}, | ||
folderIds: parseObject(this.folderIds), | ||
tags: parseObject(this.tags)?.map((item) => ({ | ||
id: item, | ||
})), | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}); | ||
|
||
$.export("$summary", `Created card "${this.title}" successfully`); | ||
return response; | ||
}, | ||
}; |
41 changes: 41 additions & 0 deletions
41
components/guru/actions/export-card-to-pdf/export-card-to-pdf.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 fs from "fs"; | ||
import stream from "stream"; | ||
import { promisify } from "util"; | ||
import guru from "../../guru.app.mjs"; | ||
|
||
export default { | ||
key: "guru-export-card-to-pdf", | ||
name: "Export Card to PDF", | ||
description: "Export a specific card identified by its ID to a PDF file. [See the documentation](https://developer.getguru.com/docs/download-cards-to-pdf)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
guru, | ||
cardId: { | ||
propDefinition: [ | ||
guru, | ||
"cardId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
headers, data, | ||
} = await this.guru.exportCardToPdf({ | ||
$, | ||
cardId: this.cardId, | ||
returnFullResponse: true, | ||
}); | ||
|
||
const fileName = headers["content-disposition"]?.split("filename=")[1]?.split("/")[1].slice(0, -1); | ||
const filePath = `/tmp/${fileName}`; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const pipeline = promisify(stream.pipeline); | ||
await pipeline(data, fs.createWriteStream(filePath)); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$.export("$summary", `Successfully exported card ID ${this.cardId} to PDF.`); | ||
return { | ||
filePath, | ||
}; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
export const SHARE_STATUS_OPTIONS = [ | ||
"TEAM", | ||
"PRIVATE", | ||
]; |
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,24 @@ | ||
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 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,190 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "guru", | ||
propDefinitions: { | ||
collection: { | ||
type: "string", | ||
label: "Collection", | ||
description: "The collection to create the card in", | ||
async options() { | ||
const data = await this.listCollections(); | ||
|
||
return data.map(({ | ||
id: value, name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
folderIds: { | ||
type: "string[]", | ||
label: "Folder Ids", | ||
description: "The IDs of the folders to create the card in", | ||
async options() { | ||
const data = await this.listFolders(); | ||
|
||
return data.map(({ | ||
id: value, title: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
tags: { | ||
type: "string[]", | ||
label: "Tags", | ||
description: "The IDs of the tags to add to the card", | ||
async options() { | ||
const { team: { id: teamId } } = await this.whoAmI(); | ||
const data = await this.listTags({ | ||
teamId, | ||
}); | ||
|
||
return data[0]?.tags.map(({ | ||
id: value, value: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})); | ||
}, | ||
}, | ||
cardId: { | ||
type: "string", | ||
label: "Card ID", | ||
description: "The ID of the card", | ||
async options({ prevContext }) { | ||
const { | ||
data, headers, | ||
} = await this.listCards({ | ||
params: { | ||
token: prevContext.token, | ||
}, | ||
}); | ||
let token; | ||
|
||
if (headers.link) { | ||
const link = headers.link.split(">")[0].slice(1); | ||
const url = new URL(link); | ||
const params = new URLSearchParams(url.search); | ||
token = params.get("token"); | ||
} | ||
return { | ||
options: data.map(({ | ||
id: value, preferredPhrase: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})), | ||
context: { | ||
token, | ||
}, | ||
}; | ||
}, | ||
}, | ||
|
||
folderId: { | ||
type: "string", | ||
label: "Folder ID", | ||
description: "The ID of the folder to export to PDF", | ||
}, | ||
}, | ||
methods: { | ||
_baseUrl() { | ||
return "https://api.getguru.com/api/v1"; | ||
}, | ||
_auth() { | ||
return { | ||
username: `${this.$auth.username}`, | ||
password: `${this.$auth.api_key}`, | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
auth: this._auth(), | ||
...opts, | ||
}); | ||
}, | ||
whoAmI(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/whoami", | ||
...opts, | ||
}); | ||
}, | ||
createCard(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/cards/extended", | ||
...opts, | ||
}); | ||
}, | ||
linkTagToCard({ | ||
cardId, tagId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "PUT", | ||
path: `/cards/${cardId}/tags/${tagId}`, | ||
headers: { | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
exportCardToPdf({ | ||
cardId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/cards/${cardId}/pdf`, | ||
responseType: "stream", | ||
...opts, | ||
}); | ||
}, | ||
listCollections(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/collections", | ||
...opts, | ||
}); | ||
}, | ||
listFolders(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/folders", | ||
...opts, | ||
}); | ||
}, | ||
listTags({ | ||
teamId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/teams/${teamId}/tagcategories`, | ||
...opts, | ||
}); | ||
}, | ||
listCards(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/search/cardmgr", | ||
returnFullResponse: true, | ||
...opts, | ||
}); | ||
}, | ||
createWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/webhooks", | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook(webhookId) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
path: `/webhooks/${webhookId}`, | ||
}); | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.
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.