Skip to content
Open
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
37 changes: 10 additions & 27 deletions components/notion/actions/append-block/append-block.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import notion from "../../notion.app.mjs";
import base from "../common/base-page-builder.mjs";
import { appendBlocks } from "notion-helper";

export default {
...base,
key: "notion-append-block",
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.11",
description: "Append new and/or existing blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)",
version: "0.4.0",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -81,16 +81,6 @@ export default {

return {};
},
methods: {
...base.methods,
chunkArray(array, chunkSize = 100) {
const chunks = [];
for (let i = 0; i < array.length; i += chunkSize) {
chunks.push(array.slice(i, i + chunkSize));
}
return chunks;
},
},
async run({ $ }) {
const { blockTypes } = this;
const children = [];
Expand Down Expand Up @@ -133,20 +123,13 @@ export default {
return;
}

const results = [];
const chunks = this.chunkArray(children);

for (const chunk of chunks) {
const { results: payload } = await this.notion.appendBlock(
this.pageId,
chunk,
);
results.push(payload);
}

const totalAppended = results.reduce((sum, res) => sum + res.length, 0);
const response = await appendBlocks({
client: await this.notion._getNotionClient(),
block_id: this.pageId,
children,
});

$.export("$summary", `Appended ${totalAppended} block(s) successfully`);
return results.flat();
$.export("$summary", "Appended blocks successfully");
return response.apiResponses;
},
};
57 changes: 57 additions & 0 deletions components/notion/actions/common/base-page-builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
} from "../../common/notion-meta-properties.mjs";
import NOTION_META from "../../common/notion-meta-selection.mjs";
import NOTION_PAGE_PROPERTIES from "../../common/notion-page-properties.mjs";
import {
createPage, createNotionBuilder,
} from "notion-helper";
import { ConfigurationError } from "@pipedream/platform";

export default {
Expand Down Expand Up @@ -299,5 +302,59 @@ export default {
});
return children.filter((child) => child !== undefined);
},
async buildPageFromDataSource({
pageContent, parentDataSourceId, parentPageId, properties = [], icon, cover,
}) {
let pageBlocks = [];
if (pageContent && pageContent.trim()) {
try {
pageBlocks = markdownToBlocks(pageContent);
} catch (error) {
throw new ConfigurationError(`Failed to convert Markdown content to Notion blocks: ${error.message}`);
}
}

// Build the Notion page using notion-helper
let pageBuilder = createNotionBuilder({
limitChildren: false,
limitNesting: false,
allowBlankParagraphs: true,
});
if (parentDataSourceId) {
pageBuilder = pageBuilder.parentDataSource(parentDataSourceId);
}
if (parentPageId) {
pageBuilder = pageBuilder.parentPage(parentPageId);
}

for (const property of properties) {
const propertyTypeCamelCase = property.type.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
pageBuilder = pageBuilder[propertyTypeCamelCase](property.label, property.value);
}

if (icon) {
pageBuilder = pageBuilder.icon(icon);
}

if (cover) {
pageBuilder = pageBuilder.cover(cover);
}

if (pageBlocks.length > 0) {
pageBuilder = pageBuilder.loop(
(page, block) => {
return page.addExistingBlock(block);
},
pageBlocks,
);
}

const page = pageBuilder.build();
const response = await createPage({
client: await this.notion._getNotionClient(),
data: page.content,
});
return response.apiResponse;
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "notion-complete-file-upload",
name: "Complete File Upload",
description: "Use this action to finalize a `mode=multi_part` file upload after all of the parts have been sent successfully. [See the documentation](https://developers.notion.com/reference/complete-a-file-upload)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "notion-create-database",
name: "Create Database",
description: "Create a database and its initial data source. [See the documentation](https://developers.notion.com/reference/database-create)",
version: "0.1.3",
version: "0.1.4",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "notion-create-file-upload",
name: "Create File Upload",
description: "Create a file upload. [See the documentation](https://developers.notion.com/reference/create-a-file-upload)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
key: "notion-create-page-from-database",
name: "Create Page from Data Source",
description: "Create a page from a data source. [See the documentation](https://developers.notion.com/reference/post-page)",
version: "1.0.4",
version: "1.1.0",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -64,7 +64,7 @@
description: "Cover [External URL](https://developers.notion.com/reference/file-object#external-file-objects)",
optional: true,
},
alert: {

Check warning on line 67 in components/notion/actions/create-page-from-database/create-page-from-database.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 67 in components/notion/actions/create-page-from-database/create-page-from-database.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "This action will create an empty page by default. To add content, use the `Page Content` prop below.",
Expand All @@ -91,35 +91,33 @@
* @returns the constructed page in Notion format
*/
buildPage(parentDataSource) {
const meta = this.buildDataSourceMeta(parentDataSource);
this.properties = utils.parseObject(this.properties);
const properties = this.buildPageProperties(parentDataSource.properties);
const children = this.createBlocks(this.pageContent);
return {
...meta,
properties,
children,
};

const propertiesArray = [];
for (const property of Object.values(parentDataSource.properties)) {
if (properties[property.id]) {
propertiesArray.push({
label: property.name,
type: property.type,
value: this[property.name] || this.properties[property.name],
});
}
}

return propertiesArray;
},
},
async run({ $ }) {
const MAX_BLOCKS = 100;
const parentPage = await this.notion.retrieveDataSource(this.parentDataSource);
const {
children, ...page
} = this.buildPage(parentPage);
const response = await this.notion.createPage({
...page,
children: children.slice(0, MAX_BLOCKS),
parent: {
data_source_id: this.parentDataSource,
},
const properties = await this.buildPage(parentPage);
const response = await this.buildPageFromDataSource({
pageContent: this.pageContent,
parentDataSourceId: this.parentDataSource,
properties,
icon: this.icon,
cover: this.cover,
});
let remainingBlocks = children.slice(MAX_BLOCKS);
while (remainingBlocks.length > 0) {
await this.notion.appendBlock(response.id, remainingBlocks.slice(0, MAX_BLOCKS));
remainingBlocks = remainingBlocks.slice(MAX_BLOCKS);
}
$.export("$summary", "Created page successfully");
return response;
},
Expand Down
73 changes: 14 additions & 59 deletions components/notion/actions/create-page/create-page.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import utils from "../../common/utils.mjs";
import notion from "../../notion.app.mjs";
import base from "../common/base-page-builder.mjs";

Expand All @@ -7,7 +6,7 @@ export default {
key: "notion-create-page",
name: "Create Page",
description: "Create a page from a parent page. [See the documentation](https://developers.notion.com/reference/post-page)",
version: "0.2.24",
version: "0.3.0",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down Expand Up @@ -49,64 +48,20 @@ export default {
meta: this.metaTypes,
});
},
methods: {
...base.methods,
/**
* Builds a page from a parent page
* @param parentPage - the parent page
* @returns the constructed page in Notion format
*/
buildPage(parentPage) {
const meta = this.buildPageMeta(parentPage);
const children = this.createBlocks(this.pageContent);

const properties = {};
if (this.title) {
properties.title = {
title: utils.buildTextProperty(this.title),
};
}

return {
...meta,
properties,
children,
};
},
splitChildrenArray(children) {
const first100Children = children.slice(0, 100);
const restOfChildren = children.slice(100);
return {
first100Children,
restOfChildren,
};
},
async appendChildren(pageId, children) {
while (children.length) {
const {
first100Children, restOfChildren,
} = this.splitChildrenArray(children);
await this.notion.appendBlock(pageId, first100Children);
children = restOfChildren;
}
},
},
async run({ $ }) {
const parentPage = await this.notion.retrievePage(this.parent);
const page = this.buildPage(parentPage);

// Notion restricts children array length to <= 100
const {
first100Children, restOfChildren,
} = this.splitChildrenArray(page.children);
page.children = first100Children;

const response = await this.notion.createPage(page);

if (restOfChildren.length) {
await this.appendChildren(response.id, restOfChildren);
}

const response = await this.buildPageFromDataSource({
pageContent: this.pageContent,
parentPageId: this.parent,
properties: [
{
label: "title",
type: "title",
value: this.title,
},
],
icon: this.icon,
cover: this.cover,
});
$.export("$summary", "Created page successfully");
return response;
},
Expand Down
2 changes: 1 addition & 1 deletion components/notion/actions/delete-block/delete-block.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
key: "notion-delete-block",
name: "Delete Block",
description: "Sets a Block object, including page blocks, to archived: true using the ID specified. [See the documentation](https://developers.notion.com/reference/delete-a-block)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: true,
openWorldHint: true,
Expand All @@ -15,7 +15,7 @@
type: "action",
props: {
notion,
infoLabel: {

Check warning on line 18 in components/notion/actions/delete-block/delete-block.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 18 in components/notion/actions/delete-block/delete-block.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "**Note:** In the Notion UI application, this moves the block to the \"Trash\" where it can still be accessed and restored.",
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.21",
version: "0.0.22",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "notion-list-file-uploads",
name: "List File Uploads",
description: "Use this action to list file uploads. [See the documentation](https://developers.notion.com/reference/list-file-uploads)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "notion-retrieve-file-upload",
name: "Retrieve File Upload",
description: "Use this action to retrieve a file upload. [See the documentation](https://developers.notion.com/reference/retrieve-a-file-upload)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "notion-send-file-upload",
name: "Send File Upload",
description: "Send a file upload. [See the documentation](https://developers.notion.com/reference/send-a-file-upload)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand Down
2 changes: 1 addition & 1 deletion components/notion/actions/update-block/update-block.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
key: "notion-update-block",
name: "Update Child Block",
description: "Updates a child block object. [See the documentation](https://developers.notion.com/reference/update-a-block)",
version: "0.0.6",
version: "0.0.7",
annotations: {
destructiveHint: true,
openWorldHint: true,
Expand All @@ -21,7 +21,7 @@
label: "Block ID",
description: "Block ID retrieved from the **Retrieve Page Content** action",
},
infoLabel: {

Check warning on line 24 in components/notion/actions/update-block/update-block.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 24 in components/notion/actions/update-block/update-block.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "**Note:** The update replaces the entire value for a given field. If a field is omitted (ex: omitting checked when updating a to_do block), the value will not be changed.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
key: "notion-update-database",
name: "Update Data Source",
description: "Update a data source. [See the documentation](https://developers.notion.com/reference/update-a-data-source)",
version: "1.0.3",
version: "1.0.4",
annotations: {
destructiveHint: true,
openWorldHint: true,
Expand Down
2 changes: 1 addition & 1 deletion components/notion/actions/update-page/update-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
key: "notion-update-page",
name: "Update Page",
description: "Update a page's property values. To append page content, use the *Append Block* action instead. [See the documentation](https://developers.notion.com/reference/patch-page)",
version: "2.0.3",
version: "2.0.4",
annotations: {
destructiveHint: true,
openWorldHint: true,
Expand All @@ -16,7 +16,7 @@
type: "action",
props: {
notion,
infoLabel: {

Check warning on line 19 in components/notion/actions/update-page/update-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 19 in components/notion/actions/update-page/update-page.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop infoLabel must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "Properties that are not set will remain unchanged.",
Expand Down
Loading
Loading