diff --git a/components/notion/actions/append-block/append-block.mjs b/components/notion/actions/append-block/append-block.mjs index dd4f4c3aae477..235e6c5ce5bb8 100644 --- a/components/notion/actions/append-block/append-block.mjs +++ b/components/notion/actions/append-block/append-block.mjs @@ -7,7 +7,7 @@ export default { name: "Append Block to Parent", description: "Append new and/or existing blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)", - version: "0.3.1", + version: "0.3.2", type: "action", props: { notion, diff --git a/components/notion/actions/duplicate-page/duplicate-page.mjs b/components/notion/actions/duplicate-page/duplicate-page.mjs index 272c7048a0912..f8f1e4bed2f24 100644 --- a/components/notion/actions/duplicate-page/duplicate-page.mjs +++ b/components/notion/actions/duplicate-page/duplicate-page.mjs @@ -7,7 +7,7 @@ export default { key: "notion-duplicate-page", name: "Duplicate Page", description: "Create a new page copied from an existing page block. [See the documentation](https://developers.notion.com/reference/post-page)", - version: "0.0.11", + version: "0.0.12", type: "action", props: { notion, diff --git a/components/notion/actions/retrieve-block/retrieve-block.mjs b/components/notion/actions/retrieve-block/retrieve-block.mjs index c5b97a176186e..de4baabe59443 100644 --- a/components/notion/actions/retrieve-block/retrieve-block.mjs +++ b/components/notion/actions/retrieve-block/retrieve-block.mjs @@ -4,7 +4,7 @@ export default { key: "notion-retrieve-block", name: "Retrieve Page Content", description: "Get page content as block objects or markdown. Blocks can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)", - version: "0.1.0", + version: "0.2.0", type: "action", props: { notion, @@ -15,33 +15,50 @@ export default { ], }, retrieveChildren: { - type: "boolean", - label: "Retrieve Content (Child Blocks)", - description: "Retrieve all the children (recursively) for the specified page. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information", + type: "string", + label: "Retrieve Children", + description: "Retrieve all the children (recursively) for the specified page, or optionally filter to include only sub-pages in the result. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information", optional: true, - default: false, + options: [ + "All Children", + "Sub-Pages Only", + "None", + ], }, retrieveMarkdown: { type: "boolean", label: "Retrieve as Markdown", - description: "Return the page content as markdown instead of block objects.", + description: "Additionally return the page content as markdown", optional: true, }, }, async run({ $ }) { + let markdownContent; if (this.retrieveMarkdown) { - const response = await this.notion.getPageAsMarkdown(this.blockId); - $.export("$summary", "Successfully retrieved page as markdown"); - return response; + markdownContent = await this.notion.getPageAsMarkdown(this.blockId); } + const { retrieveChildren } = this; + const subpagesOnly = retrieveChildren === "Sub-Pages Only"; + const block = await this.notion.retrieveBlock(this.blockId); - if (this.retrieveChildren) { - block.children = await this.notion.retrieveBlockChildren(block); + if ([ + true, + "All Children", + "Sub-Pages Only", + ].includes(retrieveChildren)) { + block.children = await this.notion.retrieveBlockChildren(block, subpagesOnly); } - $.export("$summary", `Successfully retrieved block${this.retrieveChildren - ? ` with ${block.children.length ?? 0} children` + $.export("$summary", `Successfully retrieved block${retrieveChildren + ? ` with ${block.children.length ?? 0} ${subpagesOnly + ? "sub-pages" + : "children"}` : ""}`); - return block; + return markdownContent + ? { + markdownContent, + block, + } + : block; }, }; diff --git a/components/notion/notion.app.mjs b/components/notion/notion.app.mjs index cf29d4474b88e..6215f9e9d1674 100644 --- a/components/notion/notion.app.mjs +++ b/components/notion/notion.app.mjs @@ -325,7 +325,8 @@ export default { block_id: blockId, }); }, - async retrieveBlockChildren(block, params = {}) { + async retrieveBlockChildren(block, subpagesOnly = false) { + const params = {}; const children = []; if (!block.has_children) return children; @@ -335,11 +336,11 @@ export default { next_cursor: nextCursor, } = await this.listBlockChildren(block.id, params); - children.push(...results); + children.push(...(results.filter((child) => !subpagesOnly || child.type === "child_page"))); params.next_cursor = nextCursor; } while (params.next_cursor); - (await Promise.all(children.map((child) => this.retrieveBlockChildren(child)))) + (await Promise.all(children.map((child) => this.retrieveBlockChildren(child, subpagesOnly)))) .forEach((c, i) => { children[i].children = c; }); diff --git a/components/notion/package.json b/components/notion/package.json index 28e2c1f228fcb..40006891159ed 100644 --- a/components/notion/package.json +++ b/components/notion/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/notion", - "version": "0.5.0", + "version": "0.6.0", "description": "Pipedream Notion Components", "main": "notion.app.mjs", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04e9e8d322770..8896d67d95f6e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2147,8 +2147,7 @@ importers: components/changenow: {} - components/changes_page: - specifiers: {} + components/changes_page: {} components/channeladvisor: dependencies: @@ -11106,8 +11105,7 @@ importers: components/saucelabs: {} - components/savvy_folders: - specifiers: {} + components/savvy_folders: {} components/savvycal: dependencies: