Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/notion/actions/append-block/append-block.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 31 additions & 14 deletions components/notion/actions/retrieve-block/retrieve-block.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line gets an error when retrieveChildren is set to None. Should add && retrieveChildren !== "None":

$.export("$summary", Successfully retrieved block${retrieveChildren && retrieveChildren !== "None"`

? ` with ${block.children.length ?? 0} ${subpagesOnly
? "sub-pages"
: "children"}`
: ""}`);
return block;
return markdownContent
? {
markdownContent,
block,
}
: block;
},
};
7 changes: 4 additions & 3 deletions components/notion/notion.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ export default {
block_id: blockId,
});
},
async retrieveBlockChildren(block, params = {}) {
async retrieveBlockChildren(block, subpagesOnly = false) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I've checked that all instances of this method being called did not include a params argument, so it was always initialized as an empty object - hence I changed it to a variable declaration instead.

const params = {};
const children = [];
if (!block.has_children) return children;

Expand All @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion components/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/notion",
"version": "0.5.0",
"version": "0.6.0",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand Down
6 changes: 2 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading