-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[20230][feat(workflowy)]: add create-node, search-nodes, update-node actions #21314
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
Open
vetrivigneshwaran
wants to merge
9
commits into
master
Choose a base branch
from
issue-20230-workflowy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
091a2f2
feat(workflowy): add create-node, search-nodes, update-node actions
vetrivigneshwaran cc27da2
Update pnpm-lock file
vetrivigneshwaran 587a7d5
Merge branch 'master' into issue-20230-workflowy
vetrivigneshwaran 9b1cfc0
addressed review comment
vetrivigneshwaran 5c8c32f
Changes with respect to base url and link in description
vetrivigneshwaran a05a857
change in the url
vetrivigneshwaran f596946
addressed the review comment
vetrivigneshwaran 7611bfc
Merge remote-tracking branch 'origin/master' into issue-20230-workflowy
vetrivigneshwaran 2bc868d
updated pnpm-lock file
vetrivigneshwaran 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,64 @@ | ||
| import workflowy from "../../workflowy.app.mjs"; | ||
| import { POSITIONS } from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "workflowy-create-node", | ||
| name: "Create Node", | ||
| description: "Creates a new bullet node in WorkFlowy via the beta API (POST /api/v1/nodes). Use this to add a top-level node or a child under an existing parent. To create a child node, first run **Search Nodes** to obtain a valid parent node ID and pass it as `parentNodeId`. Returns the newly created node's ID. [See the documentation](https://beta.workflowy.com/api-reference/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| workflowy, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "The main text of the new node.", | ||
| }, | ||
| note: { | ||
| type: "string", | ||
| label: "Note", | ||
| description: "Optional note (secondary text) for the node.", | ||
| optional: true, | ||
| }, | ||
| parentNodeId: { | ||
| type: "string", | ||
| label: "Parent Node ID", | ||
| description: "Free-form parent node ID under which to create this node. Leave blank to create a top-level node. To find a valid ID, first run **Search Nodes** and copy the `id` of the desired parent. Also accepts special values: `None` (root), `inbox`, `calendar`, `today`, `tomorrow`, `next_week`, or a date like `YYYY-MM-DD`.", | ||
| optional: true, | ||
| }, | ||
| layoutMode: { | ||
| propDefinition: [ | ||
| workflowy, | ||
| "layoutMode", | ||
| ], | ||
| }, | ||
| position: { | ||
| type: "string", | ||
| label: "Position", | ||
| description: "Where to place the node among its siblings. One of `top` (default) or `bottom`.", | ||
| options: POSITIONS, | ||
| optional: true, | ||
| default: "top", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.workflowy.createNode({ | ||
| $, | ||
| data: { | ||
| name: this.name, | ||
| note: this.note, | ||
| parent_id: this.parentNodeId, | ||
| layoutMode: this.layoutMode, | ||
| position: this.position, | ||
| }, | ||
| }); | ||
| const nodeId = response?.item_id ?? response?.id ?? "unknown"; | ||
| $.export("$summary", `Created node "${this.name}" with ID ${nodeId}`); | ||
| return response; | ||
| }, | ||
| }; | ||
52 changes: 52 additions & 0 deletions
52
components/workflowy/actions/search-nodes/search-nodes.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,52 @@ | ||
| import workflowy from "../../workflowy.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "workflowy-search-nodes", | ||
| name: "Search Nodes", | ||
| description: "Searches all WorkFlowy nodes by keyword. WorkFlowy has no dedicated search endpoint, so this exports all nodes (GET /api/v1/nodes-export) and filters client-side by matching the query against each node's name and note. Use this to discover node IDs before running **Create Node** (as a parent) or **Update Node**. Note: the export endpoint is rate limited to 1 request per minute. Returns matching nodes with their IDs and content. [See the documentation](https://beta.workflowy.com/api-reference/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: true, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| workflowy, | ||
| query: { | ||
| type: "string", | ||
| label: "Query", | ||
| description: "Keyword to match (case-insensitive) against each node's name and note.", | ||
| }, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "Maximum number of matching nodes to return. Min 1, max 1000. Defaults to 100.", | ||
| min: 1, | ||
| max: 1000, | ||
| default: 100, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.workflowy.exportNodes({ | ||
| $, | ||
| }); | ||
| const nodes = response?.nodes ?? []; | ||
| const lowerQuery = this.query.toLowerCase(); | ||
| const maxResults = this.maxResults ?? 100; | ||
|
|
||
| const matches = nodes | ||
| .filter((node) => { | ||
| const name = (node.name ?? "").toLowerCase(); | ||
| const note = (node.note ?? "").toLowerCase(); | ||
| return name.includes(lowerQuery) || note.includes(lowerQuery); | ||
| }) | ||
| .slice(0, maxResults); | ||
|
|
||
| $.export("$summary", `Found ${matches.length} node${matches.length === 1 | ||
| ? "" | ||
| : "s"} matching "${this.query}"`); | ||
| return matches; | ||
| }, | ||
| }; |
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,64 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import workflowy from "../../workflowy.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "workflowy-update-node", | ||
| name: "Update Node", | ||
| description: "Updates an existing WorkFlowy node's name, note, and/or layout mode (POST /api/v1/nodes/:id). Run **Search Nodes** first to obtain the target node ID. At least one of name, note, or layout mode must be provided. Because the update endpoint only returns a status, this action performs a follow-up retrieval (GET /api/v1/nodes/:id) and returns the updated node state. [See the documentation](https://beta.workflowy.com/api-reference/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| readOnlyHint: false, | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| }, | ||
| props: { | ||
| workflowy, | ||
| nodeId: { | ||
| type: "string", | ||
| label: "Node ID", | ||
| description: "The ID of the node to update. Run **Search Nodes** to find a valid node ID.", | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "New main text for the node. Provide at least one of name, note, or layout mode.", | ||
| optional: true, | ||
| }, | ||
| note: { | ||
| type: "string", | ||
| label: "Note", | ||
| description: "New note (secondary text) for the node. Provide at least one of name, note, or layout mode.", | ||
| optional: true, | ||
| }, | ||
| layoutMode: { | ||
| propDefinition: [ | ||
| workflowy, | ||
| "layoutMode", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (this.name === undefined && this.note === undefined && this.layoutMode === undefined) { | ||
| throw new ConfigurationError("At least one of Name, Note, or Layout Mode must be provided."); | ||
| } | ||
|
|
||
| await this.workflowy.updateNode({ | ||
| $, | ||
| nodeId: this.nodeId, | ||
| data: { | ||
| name: this.name, | ||
| note: this.note, | ||
| layoutMode: this.layoutMode, | ||
| }, | ||
| }); | ||
|
|
||
| const updatedNode = await this.workflowy.getNode({ | ||
| $, | ||
| nodeId: this.nodeId, | ||
| }); | ||
|
|
||
| $.export("$summary", `Updated node ${this.nodeId}`); | ||
| return updatedNode; | ||
|
michelle0927 marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }; | ||
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,15 @@ | ||
| export const BASE_URL = "https://beta.workflowy.com"; | ||
| export const VERSION_PATH = "/api/v1"; | ||
| export const LAYOUT_MODES = [ | ||
| "bullets", | ||
| "todo", | ||
| "h1", | ||
| "h2", | ||
| "h3", | ||
| "code-block", | ||
| "quote-block", | ||
| ]; | ||
| export const POSITIONS = [ | ||
| "top", | ||
| "bottom", | ||
| ]; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,72 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import { | ||
| BASE_URL, | ||
| LAYOUT_MODES, | ||
| VERSION_PATH, | ||
| } from "./common/constants.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "workflowy", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| layoutMode: { | ||
| type: "string", | ||
| label: "Layout Mode", | ||
| description: "Optional display mode for the node. One of: `bullets`, `todo`, `h1`, `h2`, `h3`, `code-block`, `quote-block`.", | ||
| options: LAYOUT_MODES, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _makeRequest({ | ||
| $ = this, method = "GET", path, params, data, | ||
| }) { | ||
| return axios($, { | ||
| method, | ||
| url: `${BASE_URL}${VERSION_PATH}${path}`, | ||
| headers: { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| params, | ||
| data, | ||
| }); | ||
| }, | ||
| createNode({ | ||
| $, data, | ||
| }) { | ||
| return this._makeRequest({ | ||
| $, | ||
| method: "POST", | ||
| path: "/nodes", | ||
| data, | ||
| }); | ||
| }, | ||
| updateNode({ | ||
| $, nodeId, data, | ||
| }) { | ||
| return this._makeRequest({ | ||
| $, | ||
| method: "POST", | ||
| path: `/nodes/${nodeId}`, | ||
| data, | ||
| }); | ||
| }, | ||
| getNode({ | ||
| $, nodeId, | ||
| }) { | ||
| return this._makeRequest({ | ||
| $, | ||
| method: "GET", | ||
| path: `/nodes/${nodeId}`, | ||
| }); | ||
| }, | ||
| exportNodes({ $ }) { | ||
| return this._makeRequest({ | ||
| $, | ||
| method: "GET", | ||
| path: "/nodes-export", | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs show the response only has
item_id.